Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: sorting and filtering oh my!

From: Pavel Lepin <p.lepin@-------.--->
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() &lt;= $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."


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent