Re: [xsl] testing for existence of an element - multiple variables

Subject: Re: [xsl] testing for existence of an element - multiple variables
From: David Carlisle <davidc@xxxxxxxxx>
Date: Thu, 4 Oct 2001 13:02:57 +0100
> I realise I am missing the point somewhere here but I cannot get my head 
> round it.

the point is that $thisone contains a string not a fragment of an XPath
expression. in C or java, if the variable x contained the string "1 + 2"
people do not expect to be able to use this in the middle of an
expression like
y = x + 3
and have this evaluate to y being 6.
But for some reason XPath users (many of them, not just you:-) expect 
to put a string in $thisone and use this in the middle of an expression
exactly analogous to the above.
 $doc1//CommonSoFar/$thisone
note here $doc1 is OK but it is not standing for the "expression" that
was used to set the variable, it is standing for its value, which will
be a node set, and the infix  // operator is taking that value as its
first argument. so if $thisone is "elemname" the above is
 $doc1//CommonSoFar/"elemname" 
and a syntax error.

anyway that's why it doesn't work, but in your case, where you just have
an element name not a more complicated expression, there's an easy fix
(which is probably in the faq for this list)

$doc1//CommonSoFar/*[name()=$thisone]

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