This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Passing a parameter from one matched template to another


Paul,

You pass parameters in XSLT using one or more <xsl:with-param> elements,
which can occur as content within the <xsl:apply-templates> and
<xsl:call-template> elements [1]. Also, <xsl:variable> elements declared
as top-level elements (i.e., children of <xsl:stylesheet>) are
accessible within all templates.

<xsl:template match="ARE">
  <xsl:apply-templates select="YOU">
    <xsl:with-param name="you-parameter">
      some content from the ARE template
    </xsl:with-param>
  </xsl:apply-templates>
</xsl:template>

<xsl:template match="YOU">
  <xsl:param name="you-parameter"/>
  ...
</xsl:template>

Is that what you're looking for?

Couple of nits:

The variable you gave does not contain well-formed XML. You probably
meant something like <ARE><YOU></NUTS></YOU></ARE>, right?

For compatibility reasons [2], the string '--' must not appear in an XML
comment. Ouch!

Beware of the parameter in your example, <xsl:param name="x"
select="''"/>. Have you figured out what the default value of $x is? Is
that what you intended?

Cheers,
Stuart


[1] XSLT 1.0, section 11.6, Passing Parameters To Templates,
http://www.w3.org/TR/xslt#element-with-param

[2] XML 1.0, section 2.5, Comments,
http://www.w3.org/TR/2000/REC-xml-20001006#sec-comments

-----Original Message-----
From: owner-xsl-list@lists.mulberrytech.com
[mailto:owner-xsl-list@lists.mulberrytech.com] On Behalf Of paul morgan
Sent: Tuesday, May 14, 2002 15:36
To: xsl-list@lists.mulberrytech.com
Subject: [xsl] Passing a parameter from one matched template to another

Is it possible to pass a parameter from one matched template to another?

That is, with the following:

    <xsl:variable name="input"><ARE><YOU><NUTS></xsl:variable>

    <xsl:apply-templates select="vendor:node-set($input)" />

I'd like each template that is matched to pass along a value (as
determined by the matched template) to the next template that is
matched.

    <xsl:template  match="ARE">
        <xsl:param name="x" select="''"/>
        <!-- create some value that should be accessed by the
             next template matched -- in my example, "YOU" -->
    </xsl:template>

    <xsl:template  match="YOU">
        <xsl:param name="x" select="''"/>
        <!-- create some value that should be accessed by the
             next template matched -- in my example, "NUTS" -->
    </xsl:template>

    <xsl:template  match="NUTS">
        <xsl:param name="x" select="''"/>
        <!-- whatever -->
    </xsl:template>


Thanks,

Paul



________________________________________________________
Outgrown your current e-mail service?
Get a 25MB Inbox, POP3 Access, No Ads and No Taglines with LYCOS MAIL
PLUS.
http://login.mail.lycos.com/brandPage.shtml?pageId=plus

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]