[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: calling template with parameters
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|