[xsl] Dynamic XPath Expression

Subject: [xsl] Dynamic XPath Expression
From: "Fraser Goffin" <goffinf@xxxxxxxxxxx>
Date: Wed, 09 Nov 2005 12:07:17 +0000
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>


Current Thread