473,387 Members | 1,863 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Using param value in xpath

I have the following
Code:
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" encoding="UTF-8"/>
<xsl:param name="myvar"/>

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="strings/$myvar">
<p><xsl:value-of select="."/></p>
</xsl:for-each>

</body>
</html>
</xsl:template>

</xsl:stylesheet>

What i want to do is to use the $myvar in the xpath expression. Its
marked in bold, but that gives me an error. I tried the concat
function, but that did also didnt work. What am I doing wrong?

Jul 20 '05 #1
3 1613
Hi,
What i want to do is to use the $myvar in the xpath expression. Its
marked in bold, but that gives me an error. I tried the concat
function, but that did also didnt work. What am I doing wrong?


Variables or parameters cannot be used in XSLT to dynamically make xpath expression.

You could use an extension function. e.g http://www.exslt.org/dyn/functions/evaluate/index.html

But I certainly wouldn't to that myself to solve your specific problem. Simple use:

'strings/*[local-name()=$myvar]'

or the lightening fast key equivalent:

<xsl:key name="node" match="strings/*" use="local-name()"/>

<xsl:template match="/">
<html>
<body>
<xsl:for-each select="key('node',$myvar)">
<p><xsl:value-of select="."/></p>
</xsl:for-each>
</body>
</html>
</xsl:template>

regards,
--
Joris Gillis (http://users.telenet.be/root-jg/me.html)
Spread the wiki (http://www.wikipedia.org)
Jul 20 '05 #2


jo********@gmail.com wrote:

<xsl:param name="myvar"/> <xsl:for-each select="strings/$myvar"> What i want to do is to use the $myvar in the xpath expression. Its
marked in bold, but that gives me an error. I tried the concat
function, but that did also didnt work. What am I doing wrong?


There is no dynamic XPath expression evaluation, what you have is not
syntactically correct.
It is hard to tell you what to use instead as I have no idea what you
want to achieve, you have not provided any information what type of
value you set the variable to.
If you have for instance a variable/param of type string with an element
name and you want to select elements with that name then
<xsl:for-each select="strings/*[name() = $myvar]">
might do what you want.
--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3
Thanks Joris and Martin,

that was exactly what i was looking for.

Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for...
3
by: Peter Rohleder | last post by:
Hi, I'm using a style-sheet where I make use of the XPATH-"following-sibling"-expression. The part which makes problems looks similar to the following code: --------------------------- ...
4
by: Jean-Christophe Michel | last post by:
Hi, I have a stylesheet with an accumulator like this <xsl:param name="new-x"> <xsl:for-each select="anode"> <mynode> <xsl:attribute name="attr"> <xsl:value select="anode/atag" />...
6
by: Ramon M. Felciano | last post by:
Helo all -- I'm trying to gain a deeper understand for what type of semi-declarative programming can be done through XML and XPath/XSLT. I'm looking at graph processing problems as a testbed for...
1
by: kurt hansen | last post by:
hi I thought that this would be easy, but maybe not so much. I want to: pass an xpath expression and a string value to a stylesheet and copy the source xml document, changing the value of...
4
by: Alexis | last post by:
Hi, I need to transform one xml document into a second xml document. They both have many nodes so xslt works fine, but there is one node I have not figure out how to transform. Here it is:...
6
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows...
2
by: shapper | last post by:
Hello, I am for days trying to apply a XSL transformation to a XML file and display the result in a the browser. I am using Asp.Net 2.0. Please, could someone post just a simple code example,...
1
by: V4mp1r3 | last post by:
Hi ! I'm making a XSL that returns distinct values from a XML Element, but the element is dynamic, so i pass it from the server as a Parameter. XSL: <?xml version="1.0" encoding="UTF-8"?>...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.