this is a follow up to this post. Basically I need to get the position() of items within a filtered and sorted collection. Any advice on how to proceed with this?
Thanks!
XML:
<?xml version="1.0" encoding="utf-8"?>
<news>
<newsItem id="1">
<title>Title 1</title>
</newsItem>
<newsItem id="2">
<title>Title 2</title>
</newsItem>
<newsItem id="3">
<title></title>
</newsItem>
<newsItem id="4">
<title></title>
</newsItem>
<newsItem id="5">
<title>Title 5</title>
</newsItem>
</news>
XSL:
<xsl:template match="/">
<ol>
<xsl:apply-templates select="/news/newsItem [string(title)][3 > position()]">
<xsl:sort order="descending" data-type="number" select="@id"/>
</xsl:apply-templates>
</ol>
</xsl:template>
<xsl:template match="newsItem">
<li>
<xsl:value-of select="title"/>
</li>
</xsl:template>
<xsl:template match="*" />
Desired Result:
- Title 5
- Title 2
Actual Result:
- Title 2
- Title 1
You should really look at my answer about context node list.
This stylesheet:
Output: