Subject: Re: [xsl] creating and accessing element in the same stylesheet From: "Charly" <cohana@xxxxxxxxxxxxxxx> Date: Tue, 16 Apr 2002 09:10:44 -0700 |
Thanks Agnes. The reason I want to do it this way. is because I have a complex template that takes data in a specific schema (format). I don't want to rewrite the template, I rather transform the data to the right format and process it with this template . ----- Original Message ----- From: "Agnes kielen" <a.kielen@xxxxxxx> To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, April 16, 2002 1:44 AM Subject: Re: [xsl] creating and accessing element in the same stylesheet > Hello Charly, > Reaccesing an element can be done by storing the element in an temporary > tree and then entering the variable. However I don't understand why you want > to do it in this way. > > Cheers, > Agnes > > <?xml version="1.0"?> > <xsl:stylesheet version="1.0" > xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> > <xsl:output method="text"/> > <xsl:variable name="temp"> > <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:variable> > > <xsl:template match="/"> > <xsl:for-each select="$temp/root/account"> > <xsl:value-of select="@name"/>, <xsl:value-of select="@value"/> > <xsl:text> > </xsl:text> > </xsl:for-each> > </xsl:template> > </xsl:stylesheet> > > > ----- Original Message ----- > From: "Charly" <cohana@xxxxxxxxxxxxxxx> > To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx> > Sent: Monday, April 15, 2002 11:58 PM > Subject: [xsl] creating and accessing element in the same stylesheet > > > > 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 > > > > > > > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list > > XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] creating and accessing el, Agnes kielen | Thread | [xsl] sum for a specific attribute, Charly |
Re: [xsl] plain txt output tips, Nathan Shaw | Date | [xsl] sub element selection, Pete . Gomez |
Month |