[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: calling template with parameters

Subject: Re: calling template with parameters
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Tue, 9 Jan 2001 12:48:57 +0000
apply template and parameter
Hi Roman,

> Why is the parameter in template "newslist" empty??

This is a classic problem in XSLT. When you pass a parameter to a
matching (as opposed to a named) template, you have to make sure that
the template is applied to nodes that match the match pattern of the
template expecting the parameter.

In your case, you're applying templates to the *root node* of your
news.xml document.  You haven't specified a template that matches the
root node, so the built-in template is used instead:

<xsl:template match="*|/">
  <xsl:apply-templates />
</xsl:template>

As you can see, this template doesn't expect any parameters, and it
doesn't pass any parameters on to any other templates; essentially the
parameter is ignored and discarded at this point.

You can do two things (in both I'm assuming that 'newslist' is the
document element of your news.xml document). First, you can define a
template that matches the root node and expects and passes on the
parameter:

<xsl:template match="/">
  <xsl:param name="newscount" />
  <xsl:apply-templates>
    <xsl:with-param name="newscount" select="$newscount" />
  </xsl:apply-templates>
</xsl:template>

Second (better), you can select the nodes that you're actually want to
apply template to in the original xsl:apply-templates rather than
relying on the built-in templates to ripple down to it:

  <xsl:apply-templates select="document('news/news.xml')/newslist">
     <xsl:with-param name="newscount" select="$count" />
  </xsl:apply-templates>

There's also the possibility that you could use a global variable to
store the count or something related to it (e.g. the 'shownews'
element); it would then be accessible within the second template
without you having to pass it as a parameter at all.

I hope that helps,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.