Re: [xsl] To pass parameters to function

Subject: Re: [xsl] To pass parameters to function
From: Jeni Tennison <mail@xxxxxxxxxxxxxxxx>
Date: Thu, 15 Feb 2001 12:57:20 +0000
Hi Nicola,

>         <xsl:variable name="sVal" select='XXXXX'/>
>         <xsl:value-of select="xsl:alignLeft($sVal,10)"/>

Here, you're setting the value of the variable $sVal to the node set
holding all the XXXXX children of the current node.  I think you
wanted to pass the string 'XXXXX', in which case you need a couple of
extra quotes in there:

   <xsl:variable name="sVal" select="'XXXXX'" />

A couple of things, though: you shouldn't really be using the XSLT
namespace for your own functions - make up one of your own - and you
can probably achieve what you want to achieve with foo:alignLeft() in
plain XSLT, e.g.:

   <xsl:variable name="sVal" select="'XXXXX'" />
   <xsl:value-of select="substring(
                            concat($sVal,
                                   substring('          ',
                                             string-length($sVal) + 1)),
                                   1, 10)" />

Or, if you prefer, define a template that does the same thing:

<xsl:variable name="large-node-set" select="document('')//node()" />
<xsl:template name="alignLeft">
   <xsl:param name="string" />
   <xsl:param name="pad" />
   <xsl:variable name="padding">
      <!-- using the Piez Method for repeating a number of times -->
      <xsl:for-each select="$large-node-set[position() &lt;= $pad]">
         <xsl:text> </xsl:text>
      </xsl:for-each>
   </xsl:variable>
   <xsl:value-of select="substring(
                           concat($string,
                                  substring($padding,
                                            string-length($string) + 1)),
                                 1, $pad)" />
</xsl:template>

and then call it with:

  <xsl:call-template name="alignLeft">
     <xsl:with-param name="string" select="$sVal" />
     <xsl:with-param name="pad" select="10" />
  </xsl:call-template>

Of course this is all based on my guess about what alignLeft does.
                                          
I hope that helps anyway,

Jeni

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



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


Current Thread