You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@xalan.apache.org by "Byington, Dale" <By...@peacetech.com> on 2000/12/12 17:23:21 UTC

xsl:sort problem

I am having some problems sorting my XML for output in my XSL stylesheet. I
am using Xalan 1.2.2.
Given the following XML:
<teams>
	<team>
		<indiv code="3000412"/>
	</team>
	<team>
		<indiv code="3000000"/>
	</team>
	<team>
		<group code="1116000"/>
		<indiv code="2104602"/>
	</team>
	<team>
		<group code="1116000"/>
		<indiv code="2102202"/>
	</team>
</teams>

and the following XSL:
<!-- sort by group code, then by indiv code -->
<xsl:template match="teams">
	<xsl:apply-templates select="team">
		<xsl:sort select="group/@code"/>
		<xsl:sort select="indiv/@code"/>
	</xsl:apply-templates>
</xsl:template>

<xsl:template match="team">
	<xsl:choose>
		<xsl:when test="count(group)!=0"><xsl:value-of
select="group/@name"/><br/></xsl:when>
		<xsl:otherwise><xsl:value-of
select="indiv/@name"/><br/></xsl:otherwise>
	</xsl:choose>
	<xsl:if test="count(group)!=0"><xsl:value-of
select="indiv/@name"/><br/></xsl:if>
</xsl:template>

The output is coming out as
indiv code = 3000412

indiv code = 3000000

group code = 1116000
indiv code = 2102202

group code = 1116000
indiv code = 2104602


The problem is that when the element for the primary key is missing, Xalan
seems to completely ignore the secondary key and picks the <team> elements
in natural order. This problem only occurs when I use Xalan to do the
transformation. When I use Internet Explorer to do the transformation, the
sort order is fine.



Dale Byington

Peace Technology, Inc.
13685 Baltimore Avenue
Laurel, MD 20707-5096
Phone:  (301) 206-9696
Fax:  (301) 206-9722