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

G

Geathaa

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:eek:utput 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
 
K

Klaus Johannes Rusch

Geathaa said:
<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)' />
 
G

Geathaa

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)' />
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top