Subject: Re: [xsl] Using for-each on user arguments [was: Re: Passing a list of arguments] From: "Mathieu Malaterre" <mathieu.malaterre@xxxxxxxxx> Date: Fri, 9 Nov 2007 15:35:17 +0100 |
On Nov 9, 2007 3:19 PM, Florent Georges <lists@xxxxxxxxxxxx> wrote: > Mathieu Malaterre wrote: > > Hi > > > <xsl:variable name="sections-list"> > > <args> > > <arg>C.8.7.1.1.2</arg> > > <arg>C.8.14.1.1</arg> > > </args> > > </xsl:variable> > > > <xsl:template match="article"> > > <xsl:param name="extract-section"/> > > <el> > > <xsl:value-of select="$extract-section"/> > > </el> > > </xsl:template> > > > <xsl:template match="/"> > > <e> > > <xsl:for-each select="$sections-list/args/arg"> > > <xsl:apply-templates select="article"> > > <xsl:with-param name="extract-section" select="."/> > > </xsl:apply-templates> > > </xsl:for-each> > > </e> > > </xsl:template> > > </xsl:stylesheet> > > The context changes within the for-each. You can either keep a > reference to the nodes you want to apply templates to, or instead use > the variable in the template rule, depending on what is semantically > better: > > <!-- > If you want a list of strings, use a list of strings. > --> > <xsl:variable name="sections-list" as="xs:string+" select=" > 'C.8.7.1.1.2', 'C.8.14.1.1'"/> > > <xsl:template match="article"> > <xsl:param name="extract-section" as="xs:string"/> > <el> > <xsl:value-of select="$extract-section"/> > </el> > </xsl:template> > > <xsl:template match="/"> > <e> > <xsl:variable name="a" as="element()+" select="article"/> > <xsl:for-each select="$sections-list"> > <xsl:apply-templates select="$a"> > <xsl:with-param name="extract-section" select="."/> > </xsl:apply-templates> > </xsl:for-each> > </e> > </xsl:template> > > or: > > <xsl:template match="article"> > <xsl:for-each select="$sections-list"> > <el> > <xsl:value-of select="."/> > </el> > </xsl:for-each> > </xsl:template> > > <xsl:template match="/"> > <e> > <xsl:apply-templates select="article"/> > </e> > </xsl:template> Hi Florent, As far as I understand in both case I am loosing '.' from the XML I am parsing. In both case the for-each make me loose the current node from the XML I am parsing. Thanks, -- Mathieu
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using for-each on user ar, Florent Georges | Thread | Re: [xsl] Using for-each on user ar, Florent Georges |
Re: [xsl] Using for-each on user ar, Florent Georges | Date | Re: [xsl] Using for-each on user ar, Florent Georges |
Month |