A
andrewmrichards
Hi all
I have a document which looks like this:
<catalog>
<item>
<label>Label 1</label>
<title>Title 1</title>
<artist>Artist 1</artist>
<format>cd</format>
</item>
<item>
<label>Label 1</label>
<title>Title 1</title>
<artist>Artist 1</artist>
<format>download</format>
</item>
<item>
<label>Label 1</label>
<title>Title 2</title>
<artist>Artist 2</artist>
<format>cd</format>
</item>
<item>
<label>Label 2</label>
<title>Title 3</title>
<artist>Artist 3</artist>
<format>cd</format>
</item>
</catalog>
What I'd like to do is use an XSL stylesheet to transform this into:
<catalog>
<label>
<labelName>Label 1</labelName>
<items>
<item>
Title 1 CD
</item>
<item>
Title 1 Download
</item>
Title 2 CD
</item
</items>
</label>
<label>
<labelName>Label 2</labelName>
<items>
<item>
Title 3 CD
</item>
</items>
</label>
</catalog>
I've tried loads of approaches, generally centered around using
position()=1 as a test, or variations of this, and they don't work - I
always end up with everything repeated for EVERY item, and I can't get
a structure where there's only one <label> structure for each label,
no matter how many items they have. I can see why they don't work -
but I can't find an approach which will.
What I want is something akin to <xsl:for-each
select="distint(label)"> in the way that the SQL SELECT DISTINCT
keyword works.
Can anyone point me in the right direction?
Many thanks
Andrew Richards
I have a document which looks like this:
<catalog>
<item>
<label>Label 1</label>
<title>Title 1</title>
<artist>Artist 1</artist>
<format>cd</format>
</item>
<item>
<label>Label 1</label>
<title>Title 1</title>
<artist>Artist 1</artist>
<format>download</format>
</item>
<item>
<label>Label 1</label>
<title>Title 2</title>
<artist>Artist 2</artist>
<format>cd</format>
</item>
<item>
<label>Label 2</label>
<title>Title 3</title>
<artist>Artist 3</artist>
<format>cd</format>
</item>
</catalog>
What I'd like to do is use an XSL stylesheet to transform this into:
<catalog>
<label>
<labelName>Label 1</labelName>
<items>
<item>
Title 1 CD
</item>
<item>
Title 1 Download
</item>
Title 2 CD
</item
</items>
</label>
<label>
<labelName>Label 2</labelName>
<items>
<item>
Title 3 CD
</item>
</items>
</label>
</catalog>
I've tried loads of approaches, generally centered around using
position()=1 as a test, or variations of this, and they don't work - I
always end up with everything repeated for EVERY item, and I can't get
a structure where there's only one <label> structure for each label,
no matter how many items they have. I can see why they don't work -
but I can't find an approach which will.
What I want is something akin to <xsl:for-each
select="distint(label)"> in the way that the SQL SELECT DISTINCT
keyword works.
Can anyone point me in the right direction?
Many thanks
Andrew Richards