![]() |
![]() | ![]() | ![]() | Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: sorting and filtering oh my! >Thread Next - Re: sorting and filtering oh my! Re: sorting and filtering oh my!To: NULL Date: 10/3/2007 12:01:00 PM
Joe Kesselman <keshlam-nospam@c...> wrote in
<jvmdnWX5hLevkJ7anZ2dnUVZ_q6hnZ2d@c...>:
> snafu7x7 wrote:
>> since the library is rather large I want the stylesheet
>> to be able to accept parameters for a range of items to
>> return (say the first 100, or the last 50, or whatever).
>> How can I accomplish this in conjunction with my sorting?
>
> If you look at the spec's example of numbering
> (http://www.w3.org/TR/xslt#number), you'll see that
> position() within the body of a for-each reports the
> position *after* sorting. So that's one approach --
> for-each over the sorted set, test position(), and only
> apply-templates if the position is within the range you're
> interested in.
I'm probably missing your point, but the same applies to
template matches (which seems only natural to me, since
both xsl:for-each and xsl:apply-templates define an
ordering on the current node list when invoked with
xsl:sort).
pavel@debian:~/dev/xslt$ a sortpos.xml
<data>
<elt-0 sort="0"/>
<elt-1 sort="2"/>
<elt-2 sort="7"/>
<elt-3 sort="1"/>
<elt-4 sort="6"/>
<elt-5 sort="8"/>
<elt-6 sort="3"/>
<elt-7 sort="4"/>
<elt-8 sort="9"/>
<elt-9 sort="5"/>
</data>
pavel@debian:~/dev/xslt$ a sortpos.xsl
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="limit" select="3"/>
<xsl:output indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="data">
<result>
<xsl:apply-templates select="*" mode="sort-limit">
<xsl:sort select="@sort"/>
</xsl:apply-templates>
</result>
</xsl:template>
<xsl:template match="@*|node()" mode="sort-limit">
<xsl:if test="position() <= $limit">
<xsl:apply-templates select="."/>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
pavel@debian:~/dev/xslt$ xsltproc sortpos.xsl sortpos.xml
<?xml version="1.0"?>
<result>
<elt-0 sort="0"/>
<elt-3 sort="1"/>
<elt-1 sort="2"/>
</result>
pavel@debian:~/dev/xslt$
--
"You hold judicial proceedings in drinking-houses!?"
"Poh! That judge is no more drunk than any magistrate of the
Old Bailey."
| ![]() | ![]() | ![]() |
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | |||
|
