Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XSLT: How to replace param name with this param's value ?

Reply
Thread Tools

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

 
 
Geathaa
Guest
Posts: n/a
 
      07-29-2003
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="1.0">

<xslutput method="html"/>

<!-- Global Parameter: Sessionid provided at runtime -->
<xslaram 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
 
Reply With Quote
 
 
 
 
Klaus Johannes Rusch
Guest
Posts: n/a
 
      07-29-2003
Geathaa wrote:

> <xslaram 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

http://www.atmedia.net/KlausRusch/


 
Reply With Quote
 
 
 
 
Geathaa
Guest
Posts: n/a
 
      07-30-2003
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 <> wrote in message
> news:<>...
> <xsl:text>objectdata.html?sessionid=</xsl:text>
> <xsl:value-of select="$sessionid" />
>
> or
>
> <xsl:value-of select='concat("objectdata.html?sessionid=", $sessionid)' />

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTML::Template->param() : You gave me an odd number of parameters to param()! Dave Perl Misc 5 04-26-2011 02:44 AM
[xslt] value of a node (name given by param) =?ISO-8859-2?Q?fr=EAdzel?= XML 1 07-03-2006 12:52 PM
&# in PARAM NAME causing problems Thomas Magma Java 2 08-12-2005 03:29 PM
Overload by deriv class param; call w base class param ectoplasm C++ 12 07-28-2005 08:20 AM
using param to access parameters with the same name homecurr Java 1 07-23-2004 01:13 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57