473,785 Members | 2,459 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XSLT: How to replace param name with this param's value ?

Hi everyone,

I want to transform a xml document containing the description of a
menu tree to HTML. The MenuTree XML contains the target URL for each
tree node. Some URL's contain parameters which are only known at
runtime though. These "runtime parameters" are also set as global
parameters in the XSLT stylesheet. What I want to do now is check the
URL defined in the XML and replace any "runtime parameter" with the
stylesheet parameter of the same name. Parameters which should be
replaced are enclosed in curly brackets (If there is any better way to
do this please let me know...)
The following example should clear things up:

---The XML---

<MenuTree>
<TreeNode>
<NodeId>1</NodeId>
<ParentNode>0 </ParentNode>
<Label>ObjectDa ta</Label>
<Action>objectd ata.html?sessio nid={sessionid} </Action>
<Target>OBJ_DAT A_MAIN</Target>
<Active>true</Active>
<Icon></Icon>
<IconOpen></IconOpen>
</TreeNode>
</MenuTree>

---The XSLT stylesheet ---

<xsl:styleshe et xmlns:xsl="http ://www.w3.org/1999/XSL/Transform"
version="1.0">

<xsl:output method="html"/>

<!-- Global Parameter: Sessionid provided at runtime -->
<xsl:param name="sessionid "/>

....

<xsl:apply-templates select="/MenuTree/TreeNode/Action"/>

....

---Desired Output ----
Let's assume that the sessionid was "1234" when calling the
transformation. The XSLT stylesheet's global parameter $sessionid is
set to "1234" and the transformation of the node
"/MenuTree/TreeNode/Action" should produce the following string as the
menu node's URL:

objectdata.html ?sessionid=1234

Thamks for your help! Greetings, Geathaa
Jul 20 '05 #1
2 4793
Geathaa wrote:
<xsl:param name="sessionid "/>

Let's assume that the sessionid was "1234" when calling the
transformation. The XSLT stylesheet's global parameter $sessionid is
set to "1234" and the transformation of the node
"/MenuTree/TreeNode/Action" should produce the following string as the
menu node's URL:

objectdata.html ?sessionid=1234


<xsl:text>objec tdata.html?sess ionid=</xsl:text>
<xsl:value-of select="$sessio nid" />

or

<xsl:value-of select='concat( "objectdata.htm l?sessionid=", $sessionid)' />

--
Klaus Johannes Rusch
Kl********@atme dia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2
Sorry, perhaps I should have mentioned that the parameter *name* is
also not known until runtime. All I know is which set of parameters my
appear in the menu tree's node's URLs (Thus I'm able to set all
possible prameters as global XSLT variables). Unfortunately I don't
know which parameter appears in which URL (The MenuTree XML is
generated dynamically by a database query).
So basically, there are 2 problems:
1) Parsing the <Target>URL</Target> to get the parameter names which
need to be replaced. (*After* parsing the above example I would know
that I have a parameter called "sessionid" )
2) Replacing the parameter's name with the parameter's value (If the
parameter's name was stored in another variable ($paramName) I would
need something like <xsl:value-of
select='concat( "objectdata.htm l?sessionid=", $$paramName)' />
Klaus Johannes Rusch <Kl********@atm edia.net> wrote in message
news:<3F******* ********@atmedi a.net>...
<xsl:text>objec tdata.html?sess ionid=</xsl:text>
<xsl:value-of select="$sessio nid" />

or

<xsl:value-of select='concat( "objectdata.htm l?sessionid=", $sessionid)' />

Jul 20 '05 #3

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

Similar topics

3
1653
by: Mike Whittemore | last post by:
I am trying to convert an HTML table into a list of name-value pairs, one pair per field in the table. I believe my XSLT is correct, but I've tried both Xalan and Saxon, which both fail with different results. Below I've listed my HTML input, my expected XML output, my XSLT, and the actual output from both Saxon and Xalan. Thanks in advance. HTML Input ---------- <html>
5
9553
by: inquirydog | last post by:
Hi- Does anyone know a way to compare whether two nodes contain the same information in xslt (the name, attributes, and all content recursivly should be the same. I am interested in the case where node ordering matters, and also the case where it doesn't, but perhaps that is an advanced topic). Ideally the method should be available to xpath expressions, so I think that creating new templates which compare nodes will not work (well,...
5
21696
by: K.Simon | last post by:
Hello, it's very often neccessary to replace strings or a single character in my stylesheets. My solution looks awful and very long. Now i thought to solve this with an array like structure but i found no solution. The original code looks like the following: <!-- The replacement-function that i'm calling --> <xsl:template name="replace-string">
5
2184
by: Gerald Aichholzer | last post by:
Hello NG, I have an XHMTL-file and would like to replace attribute values using XSLT. The XHTML-file contains the following code: <applet code="MyApplet/MyApplet.class" archive="prog/MyApplet.jar" width="100%" height="99%">
7
2869
by: Harolds | last post by:
The code below worked in VS 2003 & dotnet framework 1.1 but now in VS 2005 the pmID is evaluated to "" instead of what the value is set to: .... xmlItems.Document = pmXML // Add the pmID parameter to the XSLT stylesheet XsltArgumentList xsltArgList = new XsltArgumentList(); xsltArgList.AddParam("pmID", "", pmID); xmlItems.TransformArgumentList = xsltArgList;
2
1867
by: Michael Hamm | last post by:
I have the following XML file (simplified from the actual): <r> <o><n>1</n><si>s</si><v1>1</v1><v2>2</v2><v3>3</v3></o> <o><n>2</n><si>i</si><v1>4</v1><v2>5</v2><v3>6</v3></o> <o><n>3</n><si>s</si><v1>7</v1><v2>8</v2><v3>9</v3></o> <o><n>5</n><si>i</si><v1>10</v1><v2>11</v2><v3>12</v3></o> <o><n>6</n><si>i</si><v1>13</v1><v2>14</v2><v3>15</v3></o> </r>
12
2921
by: das | last post by:
Hello all, I am using .NET XSLT to transform an XML into another XML file. All this is fine with small files, but when tested with big files (30MB) it is taking between 1hr-2hrs to just transform the file. Here is the code snippet: XPathDocument xdoc = new XPathDocument(fs); XPathNavigator nav = xdoc.CreateNavigator(); xslt.Transform(nav, null, strWriter, null);
3
1751
by: Carles Company Soler | last post by:
Hello, I want to calculate the value of an attribute. For example <rect x="2+3" y="12"and be <rect x="5" y="12">. Is it possible using XSLT? Thanks!
3
9614
by: super.raddish | last post by:
Greetings, I am relatively new to, what I would call, advanced XSLT/XPath and I am after some advice from those in the know. I am attempting to figure out a mechanism within XSLT to compare the difference between two source documents and output node-sets which are "different" (changed or new) to new XML files using xsl:result-document To describe the problem I have provided some example data below along with my a portion of my current...
0
10325
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
10147
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
10091
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,...
1
7499
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
6739
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5381
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...
1
4050
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3645
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2879
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.