Re: node test in patern from string()

Subject: Re: node test in patern from string()
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Mon, 16 Aug 1999 21:35:03 -0400
At 99/08/16 14:34 -0400, Jon Smirl wrote:
Can anyone help me with how to use a string variable as part of a pattern?
The following is illegal but it shows what I want to do.

  <xsl:call-template name="buildEnum">
   <xsl:with-param name="enum" select="string('region')"/>
  </xsl:template>

  <xsl:template name="buildEnum">
  <xsl:param name="enum"/>
  <xsl:variable name="enums"
select="document('../common/enum.xml')/enums/$enum"/>
  </xsl:template>

The XT error occurs on the variable definition at the $enum - "expected node
test".

If the variable isn't a node set, then it cannot be used directly as a location step in a location path in this fashion, therefore, the XT behaviour is correct.


String variables are allowed in *predicates*, so you could select all element children and then filter based on the element type name:

  <xsl:variable name="enums"
select="document('../common/enum.xml')/enums/*[local-name(.)=$enum]"/>

I hope this helps.

........... Ken

--
G. Ken Holman                    mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Crane Softwrights Ltd.             http://www.CraneSoftwrights.com/s/
Box 266, Kars, Ontario CANADA K0A-2E0   +1(613)489-0999   (Fax:-0995)
Website:  XSL/XML/DSSSL/SGML services, training, libraries, products.
Practical Transformation Using XSLT and XPath      ISBN 1-894049-01-2
Next instructor-led training:                     MT'99 1999-12-05/06


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



Current Thread