Subject: Re: [xsl] calling template with parameters From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Tue, 9 Jan 2001 12:48:57 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] calling template with paramet, Heinz R., ITS P E320 | Thread | RE: [xsl] calling template with par, Kay Michael |
Re: [xsl] xsl:script: functions wri, Francis Norton | Date | [xsl] cross document id idref pair , DPawson |
Month |