Re: [xsl] Urgent-how to select node descent of a node

Subject: Re: [xsl] Urgent-how to select node descent of a node
From: David Carlisle <davidc@xxxxxxxxx>
Date: Wed, 19 Jun 2002 11:25:56 +0100
  I have 3 variable:

  $beginpath= "/html/body/blockquote"
  $tag="div"
  $endpath= "/table/tr/td/font"


  I try to get some value of nodes at:
  /html/body/blockquote/div[1]/table/tr/td/font and
  /html/body/blockquote/div[2]/table/tr/td/font
  /html/body/blockquote/div[3]/table/tr/td/font

  $beginpath/*[name()=$tag][position()=$index]//$endpath

  but evidenly it doesnt run.

If you have defined those variables to be a strings then your expression is
equivalent to

"/html/body/blockquote"/*[name()="div"][position()=$index]//"/table/tr/td/font"

which is clearly a syntax error as you can't use strings  to the left of
/.
In particular it is not at all the same as


/html/body/blockquote/*[name()="div"][position()=$index]///table/tr/td/font

(that would be a syntax error anyway, with three /// I suspect you want
/html/body/blockquote/*[name()="div"][position()=$index]//table/tr/td/font

People often seem to expect to be able to do this in XSLT but I'm not
sure why.

You don't find people expecting in C or java or most other languages
to just take variables holding strings that look like fragments of an
expression and just put them next to each other and hope the system will
evaluate the combination as an expression rather than as a string.


If you set
<xsl:variable name="beginnodes" select="/html/body/blockquote"/>
<xsl:variable name="tag" select="'div'"/>

you'd be able to go
$beginnodes/*[name()=$tag][position()=$index]//table/tr/td/font



David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

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


Current Thread