xsl-list
[Top] [All Lists]

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

2007-03-28 08:45:48
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>