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

Discussion in 'XML' started by Geathaa, Jul 29, 2003.

  1. Geathaa

    Geathaa Guest

    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
    Geathaa, Jul 29, 2003
    #1
    1. Advertising

  2. 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

    http://www.atmedia.net/KlausRusch/
    Klaus Johannes Rusch, Jul 29, 2003
    #2
    1. Advertising

  3. Geathaa

    Geathaa Guest

    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)' />
    Geathaa, Jul 30, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. philips
    Replies:
    2
    Views:
    672
    philips
    Jul 17, 2004
  2. =?ISO-8859-2?Q?fr=EAdzel?=

    [xslt] value of a node (name given by param)

    =?ISO-8859-2?Q?fr=EAdzel?=, Jul 3, 2006, in forum: XML
    Replies:
    1
    Views:
    737
    Martin Honnen
    Jul 3, 2006
  3. Replies:
    2
    Views:
    485
    Darel Finkbeiner
    Jan 11, 2007
  4. ectoplasm
    Replies:
    12
    Views:
    635
    Zorro
    Jul 28, 2005
  5. Dave
    Replies:
    5
    Views:
    651
    John Bokma
    Apr 26, 2011
Loading...

Share This Page