Subject: [xsl] creating and accessing element in the same stylesheet From: "Charly" <cohana@xxxxxxxxxxxxxxx> Date: Mon, 15 Apr 2002 14:58:26 -0700 |
Hello Friends Does anyone have any idea how to create an element in a template and accessing it with another template within the same stylesheet . I have a generic template that takes a specific format so I need to reformat my data before calling the generic template . Something that would look like : Stylesheet ---------- <xsl:stylesheet> <xsl:template match="/"> <xsl:element name="root"> <xsl:for-each select="/report/account"> <xsl:element name="{name(.)}"> <xsl:attribute name="name"> <xsl:value-of select="@id"/> </xsl:attribute> <xsl:attribute name="value"> <xsl:value-of select="sum(./detail/@value)"/> </xsl:attribute> </xsl:element> </xsl:for-each> </xsl:element> <xsl:apply-templates /> </xsl:template> <xsl:template match="/root"> <xsl:for-each select="/root/account"> <xsl:value-of select="@name"/> <xsl:value-of select="@value"/>, <br/> </xsl:for-each> <xsl:apply-templates /> </xsl:template> </xsl:stylesheet> XML Data -------- <report> <account id="X12345" description="Individual"> <detail symbol="GPRXX" price="1" value="137" qty="137" /> <detail symbol="ODP" price="21.33" value="9598.50" qty="450" /> <detail symbol="PFE" price="39.29" value="3536.10" qty="90" /> </account> <account id="A256987"> <detail symbol="ABCAX" price="11.49" value="69717.33" qty="6067.65" /> <detail symbol="WEINX" price="12.49" value="20855.92" qty="1669.81" /> </account> <account id="A254487"> <detail symbol="ABCAX" price="11.49" value="69717.33" qty="6067.65" /> <detail symbol="WEINX" price="12.49" value="20855.92" qty="1669.81" /> </account> <account id="C545251"> <detail symbol="AKAM" price="11.11" qty="965.38" value="10725.37" /> <detail symbol="SPWX" price="5.20" qty="492.49" value="2560.97" /> <detail symbol="SUNW" price="13.69" qty="221.37" value="3030.68" /> <detail symbol="AOL" price="10.92" qty="490.51" value="5356.43" /> <detail symbol="CSCO" price="6.99" qty="1480.02" value="10345.37" /> <detail symbol="YHOO" price="8.56" qty="1187.62" value="10166.07" /> </account> </report> Excepted Output --------------- X12345, 13271.6 A256987, 90573.25 A254487, 90573.25 C545251, 42184.89 Please Help . XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] expected action not xsl:p, Thomas B. Passin | Thread | Re: [xsl] creating and accessing el, Jeni Tennison |
Re: [xsl] call-template and execute, Eric Smith | Date | Re: [xsl] call-template and execute, David Carlisle |
Month |