[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: dynamic construction of path based on param

Subject: Re: dynamic construction of path based on param
From: Oleg Tkachenko <olegt@xxxxxxxxxxxxx>
Date: Wed, 22 Jan 2003 20:18:22 +0200
dynamic construction
raven wrote:
I want to dynamically construct a path based on a
param called $course. Here is my current code:

<xsl:if test='contains($course, "510")'>
	<xsl:variable name="path" select="x510" />
</xsl:if>

<xsl:if test='contains($course, "340")'>
	<xsl:variable name="path" select="x340" />
</xsl:if>


<xsl:apply-templates select='syllabus/$path'/>
A number of mistakes: local variable's scope is its parent element, so both of your variables go out of the scope immediately. Second - variables are not macros, <xsl:variable name="path" select="x510" /> means the variable is bound to *result* of evaluation of 'x510' xpath expression. And syllabus/$path is syntax error in XPath.
What you can do (but it looks a litle bit strange) is


<xsl:variable name="path">
	<xsl:if test='contains($course, "510")'>
		<xsl:value-of select="x510" />
	</xsl:if>

	<xsl:if test='contains($course, "340")'>
		<xsl:value-of select="x340" />
	</xsl:if>
</xsl:variable>

<xsl:apply-templates select='syllabus/*[local-name() = $path]'/>

But that looks like a very convolute (and namespace-buggy) version of

	<xsl:if test='contains($course, "510")'>
		<xsl:apply-templates select='syllabus/x510'/>
	</xsl:if>
	<xsl:if test='contains($course, "340")'>
		<xsl:apply-templates select='syllabus/x340'/>
	</xsl:if>

--
Oleg Tkachenko
eXperanto team
Multiconn Technologies, Israel


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



Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.