By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,619 Members | 1,534 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,619 IT Pros & Developers. It's quick & easy.

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

P: n/a
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>ObjectData</Label>
<Action>objectdata.html?sessionid={sessionid}</Action>
<Target>OBJ_DATA_MAIN</Target>
<Active>true</Active>
<Icon></Icon>
<IconOpen></IconOpen>
</TreeNode>
</MenuTree>

---The XSLT stylesheet ---

<xsl:stylesheet 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
Share this Question
Share on Google+
2 Replies


P: n/a
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>objectdata.html?sessionid=</xsl:text>
<xsl:value-of select="$sessionid" />

or

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

--
Klaus Johannes Rusch
Kl********@atmedia.net
http://www.atmedia.net/KlausRusch/
Jul 20 '05 #2

P: n/a
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.html?sessionid=", $$paramName)' />
Klaus Johannes Rusch <Kl********@atmedia.net> wrote in message
news:<3F***************@atmedia.net>...
<xsl:text>objectdata.html?sessionid=</xsl:text>
<xsl:value-of select="$sessionid" />

or

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

Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.