Re: [xsl] Global, dynamically-named variables (or equiv) in XSL

Subject: Re: [xsl] Global, dynamically-named variables (or equiv) in XSL
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 19 Jun 2003 20:55:14 +0100

> is there an alternative way to accomplish this?

I don't think you said what this is, you gave an example of your input
document (an xsd fragment) but didn't say what you are transforming it
into, so it's hard to give any specific advice.

> The problem is that none of this works as I had hoped.  First off, it
> seems like I can't declare a variable that is named dynamically (based on
> the document being transformed)

This bit is true, in common with most other languages C, java, etc you
can't take strings from the input and make variable names out of them, 
variables are compile-time things they have to be recognised before the
input is seen.


<xsl:template match="xs:element">
  <xsl:value-of select="$@type"/>
</xsl:template>

I have a hard time guessing what effect you wanted from this but perhaps

<xsl:template match="xs:element">
 <xsl:apply-templates select="/xs:schema/*[self::xs:simpleType or self::xs:complexType][@name=current()/@name]"/>
</xsl:template>


which would apply templates to the type declaration with name given by
the @name attribute. You could make this more efficient by using a key,
but best to get something working without keys first I usually find.

David

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread