xsl-list
[Top] [All Lists]

RE: Storing calculated values in global variables ?

2002-11-12 02:39:05
I can sort the elements from both the documents in ascending 
or descending order and extract the maximum and minimum value 
elements using a single stylesheet. But how do I perform 
mathematical operations on the sorted elements ? For e.g if I 
want to add the first and the last <From> element from the 
sorted list of <From> elements how can I do this and store 
this value in a global variable so that it can be reused ? 


You capture the sorted lists in result tree fragments and then use the
xx:node-set() extension function to access these as if they were source
documents:

<xsl:variable name="sorted-list-1">
  <xsl:for-each select="document('a.xml')/record">
    <xsl:sort select="key"/>
    <xsl:copy-of select="."/>
  </
</

<xsl:variable name="sorted-list-2">
  .. ditto ..
</

<xsl:variable name="sum-of-first-and-last"
   select="xx:node-set($sorted-list-1)/record[1] +
           xx:node-set($sorted-list-1)/record[last()]"/>

Michael Kay
Software AG
home: Michael(_dot_)H(_dot_)Kay(_at_)ntlworld(_dot_)com
work: Michael(_dot_)Kay(_at_)softwareag(_dot_)com 


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



<Prev in Thread] Current Thread [Next in Thread>