[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Add numbers
At 2007-10-09 10:04 -0500, Chaudhary, Harsh wrote:
I have an XML: ... I need to group together the nodes which have the same key and then I need to add the attribute "val" in all such cases. Then you are almost there. I hope the code below helps. . . . . . . Ken T:\ftemp>type harsh.xml <?xml version="1.0" encoding="UTF-8"?> <first> <second> <a val="4" key="one">b</a> <a val="2" key="two">b</a> </second> <second> <a val="3" key="one">c</a> </second> </first> T:\ftemp>type harsh.xsl <?xml version="1.0" encoding="US-ASCII"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output indent="yes"/> <xsl:key name="keys" match="*[@key]" use="@key"/> <xsl:template match="/"> <op> <xsl:for-each select="//*[@key] [generate-id(.)=generate-id(key('keys',@key)[1])]"> <xsl:element name="{@key}"> <val><xsl:value-of select="sum(key('keys',@key)/@val)"/></val> </xsl:element> </xsl:for-each> </op> </xsl:template> </xsl:stylesheet> T:\ftemp>xslt harsh.xml harsh.xsl con <?xml version="1.0" encoding="utf-8"?> <op> <one> <val>7</val> </one> <two> <val>2</val> </two> </op> T:\ftemp>
|
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
|