Subject: Re: [xsl] Using for-each on user arguments [was: Re: Passing a list of arguments] From: Florent Georges <lists@xxxxxxxxxxxx> Date: Fri, 9 Nov 2007 15:19:35 +0100 (CET) |
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> Regards, --drkm _____________________________________________________________________________ Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using for-each on user ar, Mathieu Malaterre | Thread | Re: [xsl] Using for-each on user ar, Mathieu Malaterre |
Re: [xsl] Using for-each on user ar, Mathieu Malaterre | Date | Re: [xsl] Using for-each on user ar, Mathieu Malaterre |
Month |