This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
Re: dynamic node sets
- From: Jeni Tennison <jeni at jenitennison dot com>
- To: "FRIEDLAND, STEPHEN R" <STEPHEN_R_FRIEDLAND at fleet dot com>
- Cc: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Date: Wed, 27 Mar 2002 18:19:17 +0000
- Subject: Re: [xsl] dynamic node sets
- Organization: Jeni Tennison Consulting Ltd
- References: <15C9155AB604D3118B1E0008C7B3098F0A384848@usbosmxmp02.ma.fbf1.com>
- Reply-to: xsl-list at lists dot mulberrytech dot com
Hi Stephen,
> Hi, I'm trying to get the sum of named columns but am running into
> trouble. I'd like to get the total for columns having a hasTotal
> attribute. The xsl fragment I'm trying to use is below. The problem
> is that the nodelist param is illegal (select="//$curname"). I can't
> seem to create a nodelist without hardcoding the element name
> (select="//TradeType"), but I don't know in advance which elements
> will be present and which ones have totals.
Try selecting all the elements and then filtering them to select only
those of the specified name:
//*[name() = $curname]
Personally, I'd do the xsl:for-each over the column children of the
ColumnInfo element (rather than the first TradeEntry), as that makes
it easier to work out whether you need to add a total or not for it.
I'd also step down to the relevant values rather than looking through
all the elements in the document, as doing so is more efficient. So
I'd use:
<xsl:for-each select="ColumnInfo/column">
<xsl:if test="@hasTotal">
<xsl:variable name="colname" select="@colname" />
<xsl:variable name="entries"
select="/TradeData/Trades/TradeEntry/*[name() = $colname]" />
<td>
<xsl:call-template name="getSum">
<xsl:with-param name="nodelist" select="$entries" />
</xsl:call-template>
</td>
</xsl:if>
</xsl:for-each>
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list