[Top] [All Lists]

Dynamic XPath Expression

2005-11-09 05:07:17
Is is possible to build up an XPath expression (as a string) and then use it with a select or match. For example :-

If the variable $xPath contained the string value '/root/first'

could I do :-

<xsl:copy-of select='$xPath'/>

I have to say from my initial testing this doesn't appear work and copy-of would just return the string itself not evaluate as an XPath expression, but I wondered whether there is a way of getting something like this to work ?

What I'm trying to do is compare aspects of one XML instance with another. There are a lot of comparisons I need to make and I don't really want to hard code in each individual test's XPath in an 'if' statement. So I was considering creating templates which match the portions of the document I want to compare and from that context recursing through matching each node found with the corresponding structure in the other doc :-

Doc 1                                                               Doc 2
====                                                              ====

...                                                                     ...
<Employees>                                                     <Employees>
 <Employee>                                                      <Employee>
   <FName>Fraser</FName>    <-- OK -->                <FName>Fraser</FName>
   <LName>Goffin</LName>    <-- OK -->                <LName>Goffin</LName>
</Employee> </Employee>
 <Employee>                                                      <Employee>
   <FName>Luke</FName>     <-- MISMATCH -->     <FName>Marie</FName>
   <LName>Goffin</LName>    <-- MISMATCH -->    <LName>Smith</LName>
 </Employee>                                                    </Employee>
...                                                                      ...
</Employees>                                                  </Employees>

XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>

<Prev in Thread] Current Thread [Next in Thread>