Subject: RE: [xsl] FW: How to store a node in a local variable using if or when From: Néstor Boscán <nestor.boscan@xxxxxxxxxx> Date: Fri, 1 Aug 2003 08:39:22 -0400 |
Hi Mukul Thanks for the example. That one work well. Néstor Boscán ? Consultor Teléfono Móvil: +58 414 2490162 Teléfono Oficina: +58 212 2437103 Fax Oficina: +58 212 2435796 Correo Electrónico: nestor.boscan@xxxxxxxxxx -----Original Message----- From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Mukul Gandhi Sent: Friday, August 01, 2003 12:24 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: Re: [xsl] FW: How to store a node in a local variable using if or when You may try a XSL as below .. <xsl:template match="something"> <xsl:if test="condition1"> <xsl:call-template name="process-node"> <xsl:with-param name="x" select="some-xpath1"/> </xsl:call-template> </xsl:if> <xsl:if test="condition2"> <xsl:call-template name="process-node"> <xsl:with-param name="x" select="some-xpath2"/> </xsl:call-template> </xsl:if> </xsl:template> <xsl:template name="process-node"> <xsl:param name="x"/> <xsl:for-each select="$x"> <!-- process --> </xsl:for-each> </xsl:template> Here i am creating a named template process-node. You can call it with xsl:call-template with a different parameter value, depending which condition evaluates true.. Regards, Mukul --- Néstor_Boscán <nestor.boscan@xxxxxxxxxx> wrote: > Hi > > I would like to process information from a node that > can come from two > different places in the XML tree. Because the > processing is the same I > create a variable and with a choice element I will > set the variable to > one of the two nodes. So I can figure out only two > ways of doing it that > doesn't work. Here are the two examples: > > First example use <xsl:value-of>: > > <xsl:variable name="node"/> > <xsl:choose> > <xsl:when test="condition1"> > <xsl:value-of select="/a/b/c"/> > </xsl:when> > <xsl:when test="condition2"> > <xsl:value-of select="/c"/> > </xsl:when> > </xsl:choose> > </xsl:variable> > > <xsl:for-each select="$node"> > process > </xsl:for-each> > > Will not work because <xsl:value-of> only selects > strings not nodes. So > <xsl:variable name="node" select="path"/> is not the > same as > <xsl:variable name="node"><xsl:value-of select="path"/></xsl:variable> > > Second example use "select" attribute in variable: > > <xsl:choose> > <xsl:when test="condition1"> > <xsl:variable name="node" select="/a/b/c"/> > </xsl:when> > <xsl:when test="condition2"> > <xsl:variable name="node" select="/c"/> > </xsl:when> > </xsl:choose> > </xsl:variable> > > <xsl:for-each select="$node"> > process > </xsl:for-each> > > Will not work because variable "node" is out of > scope. > > Any ideas? > > > > XSL-List info and archive: > http://www.mulberrytech.com/xsl/xsl-list > __________________________________ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com 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] FW: How to store a node i, Mukul Gandhi | Thread | Re: [xsl] FW: How to store a node i, Américo Albuquerque |
RE: [xsl] Merging attribute values , Jeff Beadle | Date | [xsl] creating an rtf/node-set from, Gary Tyree |
Month |