By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,599 Members | 1,678 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,599 IT Pros & Developers. It's quick & easy.

apply-templates not passing with-param

P: n/a
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:output 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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

--
Rémi Peyronnet
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.