Subject: [xsl] Templates, variables, and tree fragments From: "Kimberly Hahn" <Kimberly.Hahn@xxxxxxxxxx> Date: Fri, 23 Aug 2002 18:36:44 -0500 |
I have a XSLT document that is correctly transforming the data, but I need to use the output of that transformation to build some of the nodes I need. I'd like to find a way to do this in one XSLT document, and not have to run two back to back transformations. The below is a cut down version of the problem. The template for KH/Key/MD/@AskAvl can change the value in the attribute. The output of the 'row' node produced in the transform ion (RowMD template) shows the starting XML value of @AskAvl. But, I need the @AskAvl that was produced in the rebuilt 'MD' node (KH/Key/MD template) <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > <xsl:output method="html"/> <xsl:template match="*"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates select="node()"/> </xsl:copy> </xsl:template> <xsl:template match="KH/Key/MD" priority="999999"> <xsl:element name="MD"> <xsl:apply-templates select="@*"/> <xsl:call-template name="RowMD"/> </xsl:element> </xsl:template> <xsl:template match="KH/Key/MD/@AskAvl" priority="999999"> <xsl:attribute name="AskAvl"> NEW </xsl:attribute> </xsl:template> <xsl:template match="@*"> <xsl:copy-of select="."/> </xsl:template> <xsl:template name="RowMD"> <xsl:variable name="Market" select="current()"/> <xsl:element name="row"> <xsl:attribute name="data"> <xsl:value-of select="$Market/@AskAvl"/> </xsl:attribute> </xsl:element> </xsl:template> I read a snippet somewhere (don't remember where I saw it) that indicated variables could call templates, so I tried - <xsl:template name="RowMD"> <xsl:variable name="Market"> <xsl:element name="MD"> <xsl:apply-templates select="@*"/> </xsl:element> </xsl:variable > (When RowMD is called the current node is an MD node.) This produces an error stating that the market variable does not have a nodeset. But, when I changes it to - <xsl:template name="RowMD"> <xsl:variable name="AskAvl"> <xsl:apply-templates select="@AskAvl"/> </xsl:variable > <xsl:element name="row"> <xsl:attribute name="data"> <xsl:value-of select="$AskAvl"/> </xsl:attribute> </xsl:element> This appears to work, I get the value 'NEW' in the row node data attribute and in the AskAvl attribute in the MD node. But, I'd like to understand why the creation of the MD element did not work. Sample XML - <QuoteData> <Data> <Map schema="7" col0="12" col1="2" col2="2" col3="2" col4="2" col5="2" > </Data> <Data> <KH KHID="415" Type="401" QSID="5"> <Key KeyID="5505"> <MD Dep="1" BidCPID="177" BidAvl="1" AskAvl="44" AskCPID="8" /> <MD Dep="2" BidCPID="177" BidAvl="" AskAvl="3" AskCPID="8" /> </Key> <Key KeyID="552"> <MD Dep="1" BidCPID="1" BidAvl="" AskAvl="5" AskCPID="177" /> </Key> </KH> </Data> </QuoteData> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Re: quick [but difficult], Wendell Piez | Thread | Re: [xsl] Templates, variables, and, Jeni Tennison |
Re: [xsl] FOP formatting tables ins, J.Pietschmann | Date | RE: [xsl] extracting data in CDATA , Curtis Burisch |
Month |