How to resolve a XPath in XSLT

J

John Henckel

I have a data file like this.....

<top>
<graph>
<part>
<param name="mass">1 </param>
</part>
<body name="nut">
<link href="#/top/graph['1']/part['1']"/>
</body>
</graph>
</top>

Notice the "link" is a path to another node in the file. I want to use
XSLT to process this file to print a table with the name of each body
and it's mass. But I cannot figure out how to do it. This is what I
tried......

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select="top//body">

<p/> <xsl:value-of select="@name"/> has mass
<xsl:variable name="var" select="substring(link/@href,2)"/>
<xsl:value-of select="$var/param"/>

</xsl:for-each>
</xsl:template>
</xsl:stylesheet>


But this doesn't work because it says $var/param is a syntax error. Any
ideas? Am I trying to do the impossible? I do not have any control of
the input data representation.

TIA, john
 
S

Soren Kuula

Martin said:
John Henckel wrote:




There is no dynamic XPath evaluation in XSLT unless your processor
provides an extension function e.g. like Saxon here
<http://saxon.sourceforge.net/saxon6.5.5/extensions.html#evaluate>
I suppose this one could be resolved by generating an XSL stylesheet
using XSL (or whatever...), stuffing in the XPath there, and then
executing that on the original document.

There is a prefix anti-aliasing feature, of which I can never remember
the name, to enable you to write stylesheet-spewing stylesheets
(distinguish output from instructions)

Soren
 
M

Martin Honnen

Soren Kuula wrote:

I suppose this one could be resolved by generating an XSL stylesheet
using XSL (or whatever...), stuffing in the XPath there, and then
executing that on the original document.

Yes, that is also possible, most things done by an extension function
you can be solved without it by doing two or more transformation steps.
 
J

Joseph Kesselman

There is no dynamic XPath evaluation in XSLT unless your processor
provides an extension function

The "semi-standard" dynamic XPath extension is the one in the EXSLT
library. Some processors ship with part or all of EXSLT, some don't.
Check the docs.

Another solution is to use a stylesheet to generate a stylesheet with
your desired XPath, then apply that stylesheet as a separate pass.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top