[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Cast variable to node-set

Subject: Re: Cast variable to node-set
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Fri, 15 Mar 2002 18:39:33 +0000
Hi David,

> Ok, here is a sample of what's going on (a bit dumbed down for brevity):
> <xsl:variable name="cr_amt"
> select="/Transactions/Transaction/CreditAmount"/>
> <xsl:variable name="cr_under_amt" select="MinAmt/CRUnderMinAmt"/>
> <td style="text-align:right;">
>     <xsl:call-template name="displaycurrency">
>         <xsl:with-param name="node" select="$cr_amt + $cr_under_amt"/>
>         <xsl:with-param name="total">1</xsl:with-param>
>     </xsl:call-template>
> </td>
> Then inside "displaycurrency":
> <xsl:variable name="output">
>     <xsl:value-of select="sum($node)"/>
> </xsl:variable>
> The $total xsl:param tells the template to prepend the currency code
> to the value (we only show currency code for totals). The reason for
> the sum() is that I can pass either a single node or a node-set. I
> always want to sum a node-set that is passed to the template. I
> tried this:
> select="$cr_amt | $cr_under_amt"
> But that didn't work.

Hmm... that's weird. If the call looks like:

  <xsl:call-template name="displaycurrency">
    <xsl:with-param name="node" select="$cr_amt | $cr_under_amt"/>
    <xsl:with-param name="total">1</xsl:with-param>

then assuming that $cr_amt and $cr_under_amt are node sets containing
CreditAmount and CRUnderMinAmt elements as you've said, the $node
parameter should be a node set and the sum($node) function should
provide you with the sum of those nodes.

In what way didn't it work? Did you get an error message, or just not
the result that you expected to see?

> Also, there is one additional requirement, when I pass a node into
> the template like this:
> <td align="right">
>     <xsl:call-template name="displaycurrency">
>         <xsl:with-param name="node" select="$cr_under_amt"/>
>         <xsl:with-param name="total">1</xsl:with-param>
>     </xsl:call-template>
> </td>
> The node has two attributes, @currency_code and @minor_unit (you've
> seen these in my last thread). What are the chances of getting them
> into the template without using seperate params? I have them set as
> xsl:param's now:
> <xsl:param name="currency_code" select="$node/@currency_code"/>
> <xsl:param name="minor_unit" select="$node/@minor_unit"/>

You don't need to set those as parameters -- just use normal
variables. You're passing the node itself, so you can do anything to
it you can normally do - get its attributes, children, ancestors,
whatever you need.



Jeni Tennison

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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.