xsl-list
[Top] [All Lists]

Re: Need help - Getting the value of an attribute from a following-sibling

2004-08-22 02:49:21
I'd define a variable for the ID you want  - I'll call it 'followingid'.
(This just helps to make things clearer).
Then use this value in the key function (the value you pass to a key function call can be constructed any way you like - it's just a text argument)

<xsl:for-each select="Account[(_at_)label='TotalRevenue' and @period='Quarterly']/Item">

<xsl:variable name='followingid' select='following-sibling::*[1]/@id'/>

<xsl:value-of select='format-number( (key("TotalRevenue",@id) - following-sibling::*[1]
- key("ExpenseOne",$followingid) - key("ExpenseTwo",$followingid)
,"#0.0%;(#0.0%)")' />

</xsl:for-each>


Mario Grech wrote:

The problem I have is basically this:

I am using an <xsl:key/> that accepts an id attribute as a parameter. So when I use the key function I usually call it as: key(accountName, @id), which retrieves the element from the match xpath expression, with the specified id attribute. This I can do.

I would now like to pass the value of the id-attribute from the following-sibling (not the current node) into the function. But I don't know how to retrieve this attribute value so that I can pass it into the key function. Perhaps there is another way to avoid this problem?

Here is a snippet from my XSL that illustrates the problem:

<xsl:key name="TotalRevenue" match="Stock/Account[(_at_)label='TotalRevenue' and @period='Quarterly']/Item" use="@id"/> <xsl:key name="ExpenseOne" match="Stock/Account[(_at_)label='ExpenseOne' and @period='Quarterly']/Item" use="@id"/> <xsl:key name="ExpenseTwo" match="Stock/Account[(_at_)label='ExpenseTwo' and @period='Quarterly']/Item" use="@id"/>
....
<xsl:for-each select="Account[(_at_)label='TotalRevenue' and @period='Quarterly']/Item"> <xsl:value-of select='format-number( (key("TotalRevenue",@id) - following-sibling::*[1],"#0.0%;(#0.0%)")' />
</xsl:for-each>

This works fine. I look through the Items in the TotalRevenue account, and for each Item I subtract the value of the next item in the TotalRevenue account. But now I still want to loop through the items in the TotalRevenue account, but I ALSO want to subtract the value of the next Item in this account AND the values of the items in the ExpenseOne and ExpenseTwo accounts which have the SAME id (the id of the following-sibling, not the node selected in the for-each, in the TotalRevenue account).

Ideas?
Any help would be much, much appreciated.

Mario

_________________________________________________________________
Powerful Parental Controls Let your child discover the best the Internet has to offer. http://join.msn.com/?pgmarket=en-ca&page=byoa/prem&xAPID=1994&DI=1034&SU=http://hotmail.com/enca&HL=Market_MSNIS_Taglines Start enjoying all the benefits of MSN® Premium right now and get the first two months FREE*.


--+------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--+--


--
Datalucid Limited
8 Eileen Road
South Norwood
London SE25 5EJ
United Kingdom

/
tel :0208-239-6810
mob: 0794-725-9760
email: mike(_dot_)trotman(_at_)datalucid(_dot_)com

UK Co. Reg:   4383635
VAT Reg.:   798 7531 60

/



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