Subject: Re: [xsl] template accepting variable number of params From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx> Date: Wed, 28 Mar 2001 07:29:33 +0100 |
Hi Alex, > Is there any way in XSLT to have a template which accepts a variable > number of parameters? > > Ideally I'd like to be able to pass in between 3-10 phrases and > display them in a specific way. The only thing I can think of is to > have 10 parameters and not always pass them all in, but this > requires a lot of testing for null which could cause a performance > hit. Any suggestions? You could pass in some XML that contains the phrases. In the call, use the content of the parameter to create the XML: <xsl:call-template name="format-phrases"> <xsl:with-param name="phrases"> <phrase>foo</phrase> <phrase>bar</phrase> <phrase>baz</phrase> </xsl:with-param> </xsl:call-template> (Note that you can use any xsl:value-ofs and so on that you like in there.) With XSLT 1.0 you need an extension function to convert the RTF to a node set. For example, you can use saxon:node-set() if you're using Saxon: <xsl:template name="format-phrases"> <xsl:param name="phrases" select="/.." /> <xsl:for-each select="saxon:node-set($phrases)/*"> ... </xsl:for-each> </xsl:template> With XSLT 1.1, you don't need the function because there aren't such things as RTFs. If you're not happy using an extension function, then you could put all the phrases in a string with some kind of unique separator between them, and then work through that string by recursion to get the phrases. However, this is likely to be even more work than defining 10 parameters and testing whether they're null or not. 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] template accepting variable n, Alex Reuter | Thread | RE: [xsl] template accepting variab, Michael Kay |
[xsl] When test expression, Paul Dupuy, Jr. | Date | Re: [xsl] xsl, Jeni Tennison |
Month |