apply-templates not passing with-param

Discussion in 'XML' started by Daryl, Aug 9, 2004.

  1. Daryl

    Daryl Guest

    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
     
    Daryl, Aug 9, 2004
    #1
    1. Advertising

  2. 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
     
    =?ISO-8859-1?Q?R=E9mi_Peyronnet?=, Aug 9, 2004
    #2
    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. Stefan Siegl
    Replies:
    1
    Views:
    964
    Marrow
    Jul 18, 2003
  2. Geathaa
    Replies:
    2
    Views:
    700
    Geathaa
    Jul 30, 2003
  3. JKop
    Replies:
    3
    Views:
    479
  4. ectoplasm
    Replies:
    12
    Views:
    646
    Zorro
    Jul 28, 2005
  5. Dave
    Replies:
    5
    Views:
    670
    John Bokma
    Apr 26, 2011
Loading...

Share This Page