[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: dynamic node sets
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|