[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

RE: [xsl] Reusing Variables!!


Subject: RE: [xsl] Reusing Variables!!
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 9 Jan 2004 10:25:24 -0000

XSLT is not a procedural language, variables are not storage locations
whose contents you can modify as execution proceeds. You have to think
in functional terms, not procedural terms.

In your case the "function" is the concatenation of the string values of
a set of nodes. You can write this as:

<xsl:variable name="url">
 <xsl:for-each select="./breakdown[@sort='param' and @type='fixed']">
   <xsl:value-of select="@name"/>
 </xsl:for-each>
</xsl:variable>

I couldn't see why you were using an empty string as an argument to
concat(), by the way - it has no effect.

Michael Kay

> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx 
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of 
> Robert A. van Ginkel
> Sent: 09 January 2004 10:03
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Reusing Variables!!
> 
> 
> [XML]
>        <action idx="1" flag="browse">
>          <breakdown sort="page" data="index.php" />
>          <breakdown sort="param" name="entity" type="fixed" 
> data="User" />
>          <breakdown sort="param" name="action" type="fixed" 
> data="View" />
>        </action>
> [XSL]
> <xsl:for-each select="/sg/contents/menu/actions/action">
>   <xsl:variable name="url" select="./breakdown[@sort='page']/@data"/>
>   <xsl:variable name="url" select="concat($url,'1','')"/>
>   <xsl:for-each select="./breakdown[@sort='param' and @type='fixed']">
>     <xsl:variable name="url" select="concat($url,@name,'')"/>
>   </xsl:for-each>
> </xsl:for-each>
> 
> Would give:
> Sablotron error on line 136: conflicting variable bindings 'url' 
> (line number is wrong)
> I looked this up and  "Parameters are normal variables 
> according to the 
> XSLT 1.0 spec. Thus, you can't use two variables of the same 
> name in a 
> template. Libxslt and Xalan are too forgiving here. Saxon 
> would give you 
> the same error as Sablotron. Saxon is the right authority for 
> the spec 
> interpretation issues, I believe."
> This explains it, but how can I get what I want here?
> 
> 
>  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
Keywords