Hi, John,
You've hit the way I'd do it. However, XSL nearly always offers more than
one way to do things. Here's a different way to approach your problem:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="items">
<html>
<body>
<xsl:apply-templates select="item[(_at_)sortorder = 1]"/>
<xsl:apply-templates select="item[(_at_)sortorder > 1]">
<xsl:sort select="@sortorder"/>
</xsl:apply-templates>
</body>
</html>
</xsl:template>
<xsl:template match="item[(_at_)sortorder='1']">
<p class="first"><xsl:value-of select="."/></p>
</xsl:template>
<xsl:template match="item[(_at_)sortorder > 1]">
<p class="notfirst"><xsl:value-of select="."/></p>
</xsl:template>
</xsl:stylesheet>
As you can see, it is certainly not less verbose, and I doubt that it is
more efficient, but it is another way.
FWIW
Jay Bryant
Bryant Communication Services
(presently consulting at Synergistic Solution Technologies)
John <john-xsl-list(_at_)jpw3(_dot_)com>
06/01/2005 08:38 AM
Please respond to
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
cc
Subject
[xsl] First Element in Sorted List
I am hoping to to confirm something before going in the wrong direction.
My process needs to take action on the first element in a list of
elements where the logic to determine first is the lowest numeric value
of the sortorder attribute. I don't believe there is a one-line way to
do this - I believe the entire list must be sorted, and then the
position of each element after sort compared to determine if it is first.
Is there a shorter/less expensive way to code the following
<xsl:for-each select="item">
<xsl:sort select="@sortorder" data-type="number" />
<xsl:if test="position() = 1">
<!-- this is the first element in the sorted list -->
</xsl:if>
</xsl:for-each>
I searched and found examples using this technique, but nothing really
saying that this was the best or only approach.
Thanks in advance,
-John
--~------------------------------------------------------------------
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>
--~--
--~------------------------------------------------------------------
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>
--~--