A little difficult to explain the problem in a title, so here is a specific xml file example and what the code should return:
<objects>
<object type='Brick' to='Up' />
<object type='Cross' to='Down' />
<object type='Brick' to='Left' />
<object type='Brick' to='Up' />
<object type='Circle' to='Right' />
<object type='Circle' to='Right' />
</objects>
So I have 3 object types: Brich, Circle, and Cross, as well as 3 to's, Up, Down, Left, and Right. I want to use xquery to get something like:
<objects>
<object type="Brick">
<where to="Up" count="2" />
<where to="Down" count="0" />
<where to="Left" count="1" />
<where to="Right" count="2" />
</object>
<object type="Cross">
.
.
.
</objects>
basically, for each type, I want to get sub elements for right, down, left, and up with the number of times they appear for that object type. I know that since there are restrictions I can just hard-code every single count and have a bunch of let statements, but I'm hoping somebody could suggest a better way of doing this.