473,795 Members | 2,834 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:styleshe et
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:otherwis e>
<xsl:apply-templates select="@*|node ()"/>
</xsl:otherwise>
<xsl:choose>
</xsl:copy>
</xsl:template>

<xsl:template match="@*|comme nt()|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 5483

<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()=$x path-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
8627
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 ActiveXObject("MSXML2.FreeThreadedDomDocument.3.0"); xsl.async = false; xsl.load("campaignHtml.xsl"); var template = new ActiveXObject("MSXML2.XSLTemplate"); template.stylesheet = xsl;
3
11052
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. Regards, Karsten. -- The email above is not in use. Please write to k dot weinert at gmx dot net.
3
3045
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 like bla bal <center>bla</center><img> alblalba
1
2186
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
1299
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" select="'landscape'"> <xsl:variable name="pageheight"> <xsl:choose> <xsl:when
0
1116
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 file: <xsl:param name="recipe" select="3" /> I'm getting this error message pointing to 'xslArg.AddParam...' when I execute the .aspx file: Compiler Error Message: BC30188: Declaration expected.
2
1887
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" select="/.."/>. And then there is a lot of conditional processing based on this parameter. I stepped thru the code with a debugger in Oxygen and saw that the param is always empty (0 nodes selected). I am trying to figure what the original author of the...
0
1807
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 epression to be processed by XSLT. Here's my XSLT: <xsl:template match="/"> <xsl:param name = "pmtr"/>
1
3253
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"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" />
0
9522
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10443
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10216
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10002
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7543
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5437
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5565
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3728
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.