apply-templates not passing with-param

D

Daryl

Hello
I am using apply-templates and would like to pass a parameter to the
template using with-param. Using call-template passes the parameter,
but when I use apply-templates, the parameter seems to be lost. Can
parameters be passed with apply-templates? Any ideas?

<!--xml-->
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="tran2.xsl"?>
<doc>
<parameters>
<parameter name="a">
<options>2</options>
</parameter>
<parameter name="b"/>
<parameter name="c" >
<options>1</options>
</parameter>
<parameter name="d"/>
</parameters>
</doc>

<!--xsl called trans2.xsl-->
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="xml" media-type="text/xml" indent="yes"/>

<xsl:template match="/">
<xsl:element name="treeview" >
<xsl:element name="element" >
<xsl:attribute name="name">doc</xsl:attribute>
<xsl:element name="contents">

<!--this works-->

<xsl:call-template name = "parameters">
<xsl:with-param name="testParam" select="1"/>
</xsl:call-template>


<!--this does not-->
<!--
<xsl:apply-templates match="parameters">
<xsl:with-param name="testParam" select="1"/>
</xsl:apply-templates>
-->
</xsl:element>
</xsl:element>
</xsl:element>
</xsl:template>

<!--paramaters tag. Can hold options -->
<xsl:template name="parameters" match="parameters">
<xsl:param name="testParam" />

<xsl:if test="$testParam='1'">
Ok
</xsl:if>

<xsl:if test="$testParam=''">
failed
</xsl:if>

</xsl:template>
</xsl:stylesheet>

Cheers in advance
Daryl
 
?

=?ISO-8859-1?Q?R=E9mi_Peyronnet?=

Hello,
I am using apply-templates and would like to pass a parameter to the
template using with-param. Using call-template passes the parameter,
but when I use apply-templates, the parameter seems to be lost. Can
parameters be passed with apply-templates?

Hopefully yes :)
<xsl:apply-templates match="parameters">
^^^^^

I guess you meant :
<xsl:apply-templates select="doc/parameters">

1/ I do not know what does match (no error, but not it the
recommandation). "select" should do what you intended to.

2/ as you are in the root element, there is the doc element before
parameters.

Hth
 

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,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top