Reputation: 1059
I'm creating a bulleted list of sorted titles, using XSLT transformation from XML to HTML.
Right now I am printing out each of the titles in an unsorted manner:
<xsl:template match="/">
<html>
<head>
</head>
<body>
<p>This file contains correspondence: </p>
<ul>
<xsl:for-each select="ead/archdesc/dsc/c01">
<xsl:for-each select="c02">
<li><xsl:value-of select="did/unittitle"/></li>
</xsl:for-each>
</xsl:for-each>
</ul>
</body>
</html>
</xsl:template>
Each c02 element is contained within a c01 element, of which there are many. So if I put my xsl:sort element inside the second foreach loop, sorting on the unittitles, each c02 element is being sorted individually, not the full list.
My output when placing the sorting element in the second for-each loop resets the sorting after each c01 element.
<li>Kuiper</li>
<li>Oort</li>
<li>Oosterhoff</li>
<li>Schlesinger</li>
<li>Shapley</li>
<li>Sitter, A. de</li>
<li>Tisdale</li>
<li>Van Gent</li>
<li>Bosscha Observatory</li> //Sorting resets
My question is how I can sort the entire list of elements, when I have nested for-each loops in this case.
Edit: XML Source snippet
<dsc>
<c01 level="series" id="c01">
<did>
<unittitle label="Contents: ">Correspondence by correspondent (no
1-6)</unittitle>
<daogrp linktype="extended">
<daoloc label="reference"
href="http://digitalcollections.library.leiden.edu//.html"
linktype="locator"/>
</daogrp>
</did>
<c02 level="item" id="c01.1">
<did>
<unitid type="EAD">1</unitid>
<unittitle label="Contents: ">Van Gent</unittitle>
Upvotes: 0
Views: 699
Reputation: 70618
You don't need to have nested xsl:for-each
here, just use the one....
<xsl:for-each select="ead/archdesc/dsc/c01/c02">
<xsl:sort select="did/unittitle" />
<li><xsl:value-of select="did/unittitle"/></li>
</xsl:for-each>
Upvotes: 1