How to resolve a XPath in XSLT

John Henckel

Usenet Archive
Joined
May 21, 2004
Messages
2
Reaction score
0
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
 

Soren Kuula

Usenet Archive
Joined
Dec 14, 2003
Messages
168
Reaction score
0
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
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
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.
 

Joseph Kesselman

Usenet Archive
Joined
Feb 3, 2006
Messages
733
Reaction score
0
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
548,049
Messages
3,104,246
Members
248,133
Latest member
DujonT

Latest Threads

Top