Re: [xsl] function returning string with string-join()

Subject: Re: [xsl] function returning string with string-join()
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Fri, 06 Aug 2010 12:59:58 +0100
The variable is a document node, so there's no need for the string-join(), or even string(), to convert it to a string, it will happen automatically.

I'd be tempted to do:

<xsl:function name="my:filename" as="xs:string">
  <xsl:param name="input" as="xs:integer" />
  <xsl:value-of>
    <xsl:choose>
      <xsl:when test="$input eq 1">NO1</xsl:when>
      <xsl:when test="$input eq 2">NO2</xsl:when>
      <xsl:otherwise>NOx</xsl:otherwise>
    </xsl:choose>
    <xsl:text>.html</xsl:text>
   </xsl:value-of>
</xsl:function>

Michael Kay
Saxonica



On 06/08/2010 09:59, Michael M|ller-Hillebrand wrote:
Hello experts,

I find myself building functions like this (no real code!) to return a string:

<xsl:function name="my:filename" as="xs:string">
   <xsl:param name="input" as="xs:integer" />
   <xsl:variable name="strings">
     <xsl:choose>
       <xsl:when test="$input eq 1">
         <xsl:value-of select="'NO1'" />
       </xsl:when>
       <xsl:when test="$input eq 2">
         <xsl:value-of select="'NO2'" />
       </xsl:when>
       <xsl:otherwise>
         <xsl:message select="'otherwise?'" />
         <xsl:value-of select="'NOx'" />
       </xsl:otherwise>
     </xsl:choose>
     <xsl:value-of select="'.html'" />
   </xsl:variable>
   <xsl:value-of select="string-join($strings, '')" />
</xsl:function>
	
In a variable this builds a sequence of strings using individual xsl:value-of and in the end they are joined. Is this the way to do it if I cannot concat() everything in a single, large xsl:value-of?

I have a feeling that it might be simpler?

Thanks for teaching me new/old tricks :-)

- Michael

--
_______________________________________________________________
Michael M|ller-Hillebrand: Dokumentation Technology
Adobe Certified Expert, FrameMaker
Consulting and Training, FrameScript, XML/XSL, Unicode
Blog [de]: http://cap-studio.de/

Current Thread