Re: [xsl] Problem with xslt recursion

Subject: Re: [xsl] Problem with xslt recursion
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 10 Feb 2004 17:56:17 GMT
> [number($Index)]

you would have been better to have kept Index as a number rather than
forcing it back to a number.

ie don't do this:

<xsl:with-param name="Index"><xsl:value-of
select="$Index+1"/></xsl:with-param>


do this

<xsl:with-param name="Index" select="$Index+1"/>

Never use xsl:variable with content instead of a select attribute
unless you intend to do that. It is quite expensive.
You are starting with a number then generating a text node with the
string value of that number, placing that in a root node, making a result
tree fragment of that, and then converting the whole thing back to a
number with number().


  The purpose is solved but i want to know if it is the
  right thing to do....

Impossible to say given your description, but it seems unlikely that
you need recursion at all. As I said in my reply your stated aim of
concatenating the text can be done with a single line:

<xsl:copy-of select="Type/text()"/>

<xsl:variable name="fullpath"
select="concat('/a/b/',$path)"/>


This is a FAQ Xpaths are not strings, they are part of the syntax of
the language. In C or Java or most other programming languages, if you
had  a variable x with value 2 and the string "x+2"  it wouldn't be
trivial to get the value 4: you'd have to write a parser to parse the
string and access the referenced  constructs. It is the same in XPath,
if you have a string that looks like an XPath then this is no use to you
unless you have an Xpath parser that is callable at run time. Some
systems do have such an extension, eg saxon:evaluate but it is not a
standard part of the language.

In simple cases such as your first

<xsl:variable name="path">c</xsl:variable>
(which would be better as
  <xsl:variable name="path" select="'c'"/>
)
<!-- Now i am trying to access the dynamic path a/b/c

you can do

/a/b/*[name()=$path]

This really is a FAQ see the faq that is linked from the home page of
this list.

David



-- 
http://www.dcarlisle.demon.co.uk/matthew

________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________

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


Current Thread