Altova Mailing List Archives


Re: [xsl] Filling gaps in a list of values

From: Jeni Tennison <jeni@---------------->
To:
Date: 1/22/2002 4:53:00 AM
Hi Ben,

> Is it possible to sort the nodes and put them in a variable. ie
>
> <xsl:variable name="sorted">
>         <xsl:for-each select="nodes[@order]">
>                 <xsl:sort select="@order" order="descending"/>
>                 <xsl:copy-of select="current()"/>
>         </xsl:for-each>
> </xsl:variable>
>
> (I know this doesn't work but could it work with the correct lines
> of code? Or is it fatally flawed?)

Yes, you can do this, but when you set a variable via its content then
it gets set to a result tree fragment. To get any information out of
the result tree fragment, you need to convert it to a node set using
an extension node-set() function (whatever one your processor
supports).

This wouldn't be a bad method of getting the minimum and maximum
values for the recursion, considering that you get both the minimum
and maximum at the same time. You'd have to see, but it's likely that
a recursive method (or even better, a built-in extension function)
would be faster, but this is fairly simple.

If I were doing it, I'd try to make the result tree fragment quite
small, so simply make it:

  <xsl:variable name="minAndMax-rtf">
    <xsl:for-each select="node[@order]">
      <xsl:sort select="@order" order="descending"
                data-type="number" />
      <xsl:choose>
        <xsl:when test="position() = 1">
          <max><xsl:value-of select="@order" /></max>
        </xsl:when>
        <xsl:when test="position() = last()">
          <min><xsl:value-of select="@order" /></min>
        </xsl:when>
      </xsl:choose>
    </xsl:for-each>
  </xsl:variable>

And then do:

  <xsl:variable name="minAndMax"
                select="exsl:node-set($minAndMax-rtf)/*" />
  <xsl:call-template name="countDown">
    <xsl:with-param name="from" select="$minAndMax/max" />
    <xsl:with-param name="to" select="$minAndMax/min" />
  </xsl:call-template>

Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

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.