Dynamic parameter names in xsl

  • Thread starter systemutvecklare
  • Start date
S

systemutvecklare

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
 
J

Joris Gillis

Tempore 18:11:56 said:
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.
 
D

Dimitre Novatchev

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
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top