RE: [xsl] Confused using a loop...

Subject: RE: [xsl] Confused using a loop...
From: "Austin, Darrel" <Darrel.Austin@xxxxxxxxxxxxxxxxxx>
Date: Wed, 28 Mar 2007 10:45:15 -0500
> To learn how xsl:sort works, I suggest you use xsl:value-of
> right after the statement that should be doing the sorting:
>
> <xsl:sort select="some/Xpath">
> <sort-by>
>     <xsl:value-of select="some/Xpath">
> </sort-by>

I get an odd error when I try to do that.

If I have this:

<xsl:for-each select="//menuItem[ancestor-or-self::menuItem/pageID =
$pageID]">
		<xsl:sort select="substring(lastUpdate,1,4)"
order="descending" /> <!-- year  -->
		<xsl:sort select="substring(lastUpdate,6,2)"
order="descending" /> <!-- month -->
		<xsl:sort select="substring(lastUpdate,9,2)"
order="descending" /> <!-- day   -->
		<xsl:if test="position() &lt; $numberOfItemsToList">
			<xsl:call-template name="createItem" />
		</xsl:if>
</xsl:for-each>

It seems to work. But once I add in a value-of statement:

<xsl:for-each select="//menuItem[ancestor-or-self::menuItem/pageID =
$pageID]">
		<xsl:sort select="substring(lastUpdate,1,4)"
order="descending" /> <!-- year  -->
		<xsl:value-of select="pageID" />
		<xsl:sort select="substring(lastUpdate,6,2)"
order="descending" /> <!-- month -->
		<xsl:sort select="substring(lastUpdate,9,2)"
order="descending" /> <!-- day   -->
		<xsl:if test="position() &lt; $numberOfItemsToList">
			<xsl:call-template name="createItem" />
		</xsl:if>
</xsl:for-each>

I get this error:

XsltException: 'xsl:sort' cannot be a child of 'xsl:for-each' element.

Which is confusing, as it works just fine with xsl:sort being a child of
xsl:for-each UNTIL I add in a value-of statement.

-Darrel

Current Thread