Loading ...
Sorry, an error occurred while loading the content.

xsl:call-template

Expand Messages
  • astragh
    Hi to the forum, I am using: What I am having a problem with is being able to call on a template at a particular node
    Message 1 of 2 , Apr 12, 2005
    • 0 Attachment
      Hi to the forum,

      I am using:
      <xsl:call-template name="myTemplate"/>
      What I am having a problem with is being able to call on a template at
      a particular node level. The only way I have managed to get it working
      is by using:
      <xsl:for-each select="myChildNode">
      <xsl:call-template...>
      </xsl:for-each>
      The problem with using this is that I know there is only one childnode
      and never more than one, it seems pointless to call a for each knowing
      there will only be one node. Is there a way to call a template and be
      able to pass in a node level?

      Many thanks for any help on the matter...

      Kind regards,

      -George
    • Mike Trotman
      You can pass parameters to any template - whether called by name or matched from apply-templates. E.g.
      Message 2 of 2 , Apr 12, 2005
      • 0 Attachment
        You can pass parameters to any template - whether called by name or
        matched from apply-templates.

        E.g.
        <xsl:call-template name='myTemplate'>
        <xsl:with-param name='nodelevel'
        select='count(ancestor::something-or-other)'/>
        </xsl:call-template>

        <xsl:template name='myTemplate'>
        <xsl:param name='nodelevel' select='default-value'/>
        ......
        </xsl:template>

        Or

        <xsl:template match='myChildNode'>
        <xsl:param name='nodelevel' select='default-value'/>
        ......
        </xsl:template>

        Or even

        <xsl:template name='myTemplate' match='myChildNode'>
        <xsl:param name='nodelevel' select='default-value'/>
        ......
        </xsl:template>

        You can also use mode on xsl:apply-templates to determine which set is
        allowed to match.


        I'm not sure if that answers your question
        or whether you were asking how to determine a node level (whatever that is)
        when count(ancestor::....) or xsl:number may help.

        Mike

        astragh wrote:

        >Hi to the forum,
        >
        >I am using:
        ><xsl:call-template name="myTemplate"/>
        >What I am having a problem with is being able to call on a template at
        >a particular node level. The only way I have managed to get it working
        >is by using:
        ><xsl:for-each select="myChildNode">
        ><xsl:call-template...>
        ></xsl:for-each>
        >The problem with using this is that I know there is only one childnode
        >and never more than one, it seems pointless to call a for each knowing
        >there will only be one node. Is there a way to call a template and be
        >able to pass in a node level?
        >
        >Many thanks for any help on the matter...
        >
        >Kind regards,
        >
        >-George
        >
        >
        >
        >


        --
        No virus found in this outgoing message.
        Checked by AVG Anti-Virus.
        Version: 7.0.308 / Virus Database: 266.9.6 - Release Date: 11/04/2005
      Your message has been successfully submitted and would be delivered to recipients shortly.