This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Creating a temporary tree in memory?


Hi Khalid,

> Can I create a tree, like the one below using xslt
>
> <root-node>
> <node>1</node>
> <node>2</node>
> <node>3</node>
> </root-node>
>
> and then get sum of all of the above nodes.something like sum(node)
> that would return 6.

If you need to dynamically create this tree, then you can build the
tree with:

  <xsl:variable name="node-rtf">
    <node>1</node>
    <node>2</node>
    <node>3</node>
  </xsl:variable>

But you then need to use the appropriate node-set() extension function
for your processor to convert the result tree fragment to a node set,
in order to sum the values of the node elements. For example with
MSXML this would be:

  sum(msxsl:node-set($node-rtf)/node)

If you don't need to dynamically create the tree, then you can just
include it at the top level of your stylesheet (though you'll have to
put the root-node element in a namespace) and access it through the
document() function:

  sum(document('')/xsl:stylesheet/my:root-node/node)
  
Cheers,

Jeni

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


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]