Hi!
I have a particular problem that I can't seem to solve.
Is it possible to select all nodes using xpath and xslt without the use of additional templates or for-each?
Example xml:
<aaa id="11">
<aaa id="21"></aaa>
<bbb id="22">
<aaa id="31"></aaa>
<bbb id="32"></bbb>
<ccc id="33"></ccc>
<ddd id="34"></ddd>
<ddd id="35"></ddd>
<ddd id="36"></ddd>
</bbb>
<ccc id="23"></ccc>
<ccc id="24"></ccc>
</aaa>
A user has the ability to type in an xpath expression through a form, such as:
//aaa/bbb/ddd/@id
The user would expect to receive the ids from:
<ddd id="34"></ddd>
<ddd id="35"></ddd>
<ddd id="36"></ddd>
Outputting:
34 35 36
The only ways I have been able to achieve this is by using additional templates and for-each:
For-each way:
<xsl:template match="/">
<html>
<body>
<xsl:for-each select="//aaa/bbb/ddd">
<tr>
<td>
<xsl:value-of select="@id" />
</td>
</tr>
</xsl:for-each>
</body>
</html>
</xsl:template>
Additional template way:
<xsl:template match="/">
<html>
<body>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="//aaa/bbb/ddd">
<xsl:value-of select="@id"/>
</xsl:template>
Each of these examples require extra work to detach the @id from the original expression. I would like to use the user inputted expression as is, and just plug it in somewhere.
I have tried the following, which I thought would select all, but it only returns the first instance:
<xsl:template match="/">
<html>
<body>
<xsl:value-of select="//aaa/bbb/ddd/@id"/>
</body>
</html>
</xsl:template>
Is there a solution to my problem (i.e. a way to just plug in the user inputted expression as is?)
EDIT: Note - I need a solution that will work with any xpath expression given by the user.. no matter how complex.
Let me know if you need any further clarification.. I tried my best to explain it, but maybe I didn't do that very well.. Thank you in advance for your patience!
Thanks! :)