The problem with what you have is:
<xsl:variable name="elementName" select="@nodeName" /> ... <xsl:value-of select="/ROOT/DATASET/DATA[$pos]/*[name() = $elementName]" />
is that it assumes elementName is just one element name. If this is an arbitrary XPath expression, the test fails.
The second problem that you will encounter (or perhaps already have) is that attribute value templates are not allowed in select clauses, so you cannot do something simple:
<xsl:value-of select="/ROOT/DATASET/DATA[$pos]/{$elementName}" />
You need something that will dynamically create an XPath expression for the element you are looking for, and then dynamically evaluate that expression.
For a solution, I turned to the EXSLT evaluate() function in the dynamic library. I had to use it twice: once to create the entire XPath expression representing the request, and once to evaluate this request. The advantage of this approach is that you get access to evaluate full XPath parsing and features.
<xsl:variable name="elementLocation" select="@nodeName" /> <xsl:variable name="query" select="concat('/ROOT/DATASET/DATA[$pos]/', dyn:evaluate('$elementLocation'))"/> ... <xsl:value-of select="dyn:evaluate($query)"/>
where the dyn namespace is declared at the top as http://exslt.org/dynamic . Finding out where to quote here is difficult, and it took me several attempts to get the right.
Using them instead of the elementName name and expression expression, I get:
<html xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:dyn="http://exslt.org/dynamic"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Test</title> </head> <body><table border="1"> <tr> <td>Foo Bar</td> <td>Fizz</td> </tr> <tr> <td>testBar</td> <td>testFizz</td> </tr> <tr> <td>testBar2</td> <td>testFizz2</td> </tr> </table></body> </html>
what i think you are looking for.
Unfortunately, I do not understand MSXML, so I can’t say if your particular XSLT processor supports this extension or something like that.