[xsl] xsl:sort for the first child element

Subject: [xsl] xsl:sort for the first child element
From: Maik Stührenberg <Maik.Stuehrenberg@xxxxxxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 03 Jun 2003 11:55:07 +0200
Hello,

I have a problem regarding xsl:sort. Using an XML element like this.

<Bibitem Type="Book" Label="TEI">
	<Editor>
		<Given>C.M.</Given>
		<Family>Sperberg-McQueen</Family>
	</Editor>
	<Editor>
		<Given>L.</Given>
		<Family>Burnard</Family>
	</Editor>
	<Title>TEI P4: Guidelines for Electronic Text Encoding and Interchange</Title>
	<Address>XML Version: Oxford, Providence, Charlottesville, Bergen</Address>
	<Year>2002</Year>
</Bibitem>

it is no problem to sort the Bibitems according their Author or Editor elements with this stylesheet template:

...
<xsl:if test="Bibitem/@Type='Book'">
	<xsl:for-each select="Bibitem[@Type='Book']">
		<xsl:sort select="Author[1]/Family | Editor[1]/Family | Organization"/>
		<p>
			<xsl:apply-templates select="."/>
		</p>
	</xsl:for-each>
</xsl:if>
...

Note that all three elements are allowed as 'author' of a Bibitem: Author, Editor and Organization.
The problem is that if I use a Bibitem with both an Author or Editor element and an Organization element as well (which is also allowed according to the DTD), the xsl:sort breaks ("a sequence of more than one item is not allowed here" - of course). XSLT processor is Saxon 7.5.1


<Bibitem Type="Book" Label="TEI">
	<Editor>
		<Given>C.M.</Given>
		<Family>Sperberg-McQueen</Family>
	</Editor>
	<Editor>
		<Given>L.</Given>
		<Family>Burnard</Family>
	</Editor>
	<Title>TEI P4: Guidelines for Electronic Text Encoding and Interchange</Title>
	<Organization>Text Encoding Initiative Consortium</Organization>
	<Address>XML Version: Oxford, Providence, Charlottesville, Bergen</Address>
	<Year>2002</Year>
</Bibitem>

I tried to use xsl:sort as child element of xsl:choose/xsl:when, but it's not allowed. What I need is to check that the xsl:sort is only used on the first child element of Bibitem - regardless if it is Author, Editor or Organization. I tried the following without any success
<xsl:sort select="child::Author[1]/Family[position()=1] | child::Editor[1]/Family[position()=1] | child::Organization[position()=1]"/>
I know there were a lot of questions about getting the first child element, but I found none regarding xsl:sort. I had a look at Dave Pawson's FAQ too.
Any help would be appreciated.


Kind regards,

Maik Stührenberg


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread