[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Returning a string from a function


Subject: Re: [xsl] Returning a string from a function
From: Barry Lay <blay@xxxxxxxxxxxxxxxxxxx>
Date: Wed, 09 Jun 2004 19:00:47 -0400

Thank you very much sir. I am still learning XSLT 2.0 and this gives me a chance to examine the enhancements to the expression syntax.

Michael Kay wrote:

If the select expression in xsl:value-of is returning a sequence of strings,
and you want the strings joined together without a separator, you can
specify separator="" on the xsl:value-of instruction (the default value is
separator=" ", a single space).

However, If you want to return a string from the function, rather than a
text node, I would suggest using xsl:sequence rather than xsl:value-of. You
will then need to use string-join() to merge the strings in the sequence.

To show you an alternative coding style, I would be inclined to write this
function as:

<xsl:function name="local:logicalName" as="xs:string">
<xsl:param name="name" as="xs:string"/>
<xsl:variable name="words" as="element()*"
select="$locals/lookup/words/word"/>
<xsl:variable name="mapped-words" as="xs:string*" select="
for $substring in tokenize($name, '_') return
if ($words[@physical=$substring])
then if ($words[@physical=$substring and @logical eq '*'])
then $substring
else $words[@physical=$substring]/@logical
else if ($words[@shortPhysical=$substring])
then if ($words[@shortPhysical=$substring and @logical='*'])
then $substring
else $words[@shortPhysical=$substring]/@logical
else concat(substring(., 1, 1), lower-case(substring(., 2)))
"/>
<xsl:sequence select="string-join($mapped-words, '')"/>
</xsl:function>


Not tested!



I'll do that part.

Barry


Current Thread
Keywords