Dynamic parameter names in xsl

Discussion in 'XML' started by systemutvecklare@gmail.com, Sep 8, 2005.

  1. Guest

    Hi!

    I have an application that generates an html-form from an xml-file
    using an xsl-file. My problem is that I want the xsl to use some
    "unknown" parameters that I pass to the xslt processor before
    processing the xml. The parameters are not totally unknown but they are
    not static, they are built by an attribute in the xml and a constant
    name.

    Is it possible to define a "runtime" parameter and use the value passed
    to the xslt processor?

    xsl example:
    .... begin code ...
    <!-- BUILD PARAMETER NAME -->
    <xsl:variable name="param_name"><xsl:value-of
    select="@name"/>_T</xsl:variable>
    <!-- DEFINE PARAMETER -->
    <xsl:param name="$param_name"/>
    <!-- USE PARAMETER -->
    <xsl:if test="$param_name = 'some_value'">do something</xsl:if>
    .... end code ...

    Any other solution to this problem is appreciated

    Thanx!
    /Andreas
    , Sep 8, 2005
    #1
    1. Advertising

  2. Joris Gillis Guest

    Tempore 18:11:56, die Thursday 08 September 2005 AD, hinc in foro {comp.text.xml} scripsit <>:

    > Is it possible to define a "runtime" parameter and use the value passed
    > to the xslt processor?


    No, you'll have to redesign your xslt.
    --
    Joris Gillis (http://users.telenet.be/root-jg/me.html)
    Deserta faciunt et innovationem appelant
    Joris Gillis, Sep 8, 2005
    #2
    1. Advertising

  3. Use a single xsl:param, whose value is a node-set that combines many
    name-value pairs. Then you can use this "aggregate parameter" (or
    "environment") like this:

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:myParam="my:myParam"
    exclude-result-prefixes="xsl myParam">

    <xsl:eek:utput omit-xml-declaration="yes"/>

    <myParam:param>
    <param name="param1">
    <value>xxx1</value>
    </param>
    <param name="param2">
    <value>xxx2</value>
    </param>
    <param name="param3">
    <value>xxx3</value>
    </param>
    </myParam:param>

    <xsl:param name="pallParams"
    select="document('')/*/myParam:*[1]/*"/>

    <xsl:template match="/">
    <xsl:value-of select=
    "$pallParams[@name='param2']/value"/>
    </xsl:template>
    </xsl:stylesheet>


    Cheers,
    Dimitre Novatchev




    <> wrote in message
    news:...
    > Hi!
    >
    > I have an application that generates an html-form from an xml-file
    > using an xsl-file. My problem is that I want the xsl to use some
    > "unknown" parameters that I pass to the xslt processor before
    > processing the xml. The parameters are not totally unknown but they are
    > not static, they are built by an attribute in the xml and a constant
    > name.
    >
    > Is it possible to define a "runtime" parameter and use the value passed
    > to the xslt processor?
    >
    > xsl example:
    > ... begin code ...
    > <!-- BUILD PARAMETER NAME -->
    > <xsl:variable name="param_name"><xsl:value-of
    > select="@name"/>_T</xsl:variable>
    > <!-- DEFINE PARAMETER -->
    > <xsl:param name="$param_name"/>
    > <!-- USE PARAMETER -->
    > <xsl:if test="$param_name = 'some_value'">do something</xsl:if>
    > ... end code ...
    >
    > Any other solution to this problem is appreciated
    >
    > Thanx!
    > /Andreas
    >
    Dimitre Novatchev, Sep 8, 2005
    #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. Paddy McCarthy
    Replies:
    3
    Views:
    708
    Anthony J Bybell
    Sep 24, 2004
  2. Bob
    Replies:
    1
    Views:
    382
    Lucas Tam
    Jul 30, 2004
  3. Lewis G. Pringle, Jr.
    Replies:
    0
    Views:
    600
    Lewis G. Pringle, Jr.
    Sep 30, 2003
  4. Replies:
    1
    Views:
    3,600
    A. Bolmarcich
    May 27, 2005
  5. enggr
    Replies:
    0
    Views:
    1,632
    enggr
    Jun 30, 2010
Loading...

Share This Page