473,499 Members | 1,660 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Global xsl:param containing xpath expression string

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 the node described
by the xpath expression, to the new value.

It seems like it should look something like:

<?xml version="1.0"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

<xsl:param name="xpath-string"/>
<xsl:param name="new-value"/>

<xsl:template match="/|*">
<xsl:copy>
<xsl:choose>
<xsl:when test="is current node the desired node?">
<xsl:call-template name="update-selected-node"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="@*|node()"/>
</xsl:otherwise>
<xsl:choose>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|comment()|processing-instruction()">
<xsl:copy/>
</xsl:template>

<xsl:template name="update-selected-node">
<xsl:value-of select="new-value"/>
</xsl:template>

</xsl:stylesheet>
How do you select or test for the node specified by $xpath-string?
Can you put the $xpath-string into a xsl:template match attribute?

thanks.
Jul 20 '05 #1
1 5442

<xsl:param name="xpath-string"/>


XSLT variables can not be bound to Xpath expressions, only to strings
(and other things) so if you need to evaluate a string as an Xpath at run
time you need to have an Xpath parser and evaluator available at run
time. Some systems provide such an extension function (eg
saxon:evaluate()
but in pure XSLT it isn't really possible. in simple cases, eg you just
want to pass in an element name rather than a full xpath, you can use an
Xpath of the form
//*[name()=$xpath-string]
to select elements with a name passed in as a parameter.
or in the form you have it
replace
<xsl:when test="is current node the desired node?">
by
<xsl:when test="name()=$xpath-string">
would work do long as xpath-string is just an element or attribute
name.
David
Jul 20 '05 #2

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

Similar topics

5
8593
by: ipg | last post by:
I am running into issues passing a parameter (that is a XML string) into a stylesheet and using msxsl:node-set to parse the string. Can someone please explain why. my html: var xsl = new...
3
11041
by: Karsten Weinert | last post by:
Hi! Can you please explain to me the difference between a xsl:param and a xsl:variable? Since I can assign a value to both only once, what's the point? A small example would help me a lot. ...
3
3019
by: Tjerk Wolterink | last post by:
Hello i have xml code like this: <page:page xmlns:page="namespacefor page"> <page:section> <page:header> <b>Hello</b>There </page:header> <page:content> --- HTML CODE like: <i>Y</i>es i...
1
2171
by: Tjerk Wolterink | last post by:
Xsl stylesheet can accept parameters, but can you also give an array-data-type parameter?? With xsl parameters i mean these: Well i solved my problem but these <xsl:param name="param1"/>
0
1287
by: kirashet | last post by:
Hello everybody, I tried to make a XSL:FO - Sheet where I can control if the PDF should be printed in portrait or landscape. My results so far: <xsl:param name="printingtype"...
0
1107
by: Andrew M | last post by:
I have another newbie xml/.net question. All apologies. I'm trying to get an aspx file to modify an XSLT file based on a querystring. ie. recipe.aspx?recipe=3 will add this line to the XSLT...
2
1867
by: junkblog747 | last post by:
What will the expression "/.." in the attribute select="/.." return? I just inherited a huge stylesheet to maintain which has a lot of parameters such as <xsl:param name="myParam"...
0
1763
by: SamStamport | last post by:
Hello, I have coded a C# program that passes an argument list to my XSLT file. I get no errors, but I don't get any output either. Here's what I want to do: pass a parameter that is an XPath...
1
3238
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
7014
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
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
7229
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...
0
5485
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4921
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3108
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3103
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
311
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.