xsl-list
[Top] [All Lists]

Returning a string from a function

2004-06-09 14:41:43
I have the following in a stylesheet:

<xsl:function name="local:logicalName">
 <xsl:param name="name"/>

 <xsl:analyze-string select="$name" regex="_">
   <xsl:non-matching-substring>
   <xsl:variable name="substring" select="."/>
     <xsl:choose>
       <xsl:when test="$locals/lookup/words/word[(_at_)physical=$substring]">
         <xsl:choose>
<xsl:when test="$locals/lookup/words/word[(_at_)physical=$substring and @logical='*']">
             <xsl:value-of select="$substring"/>
           </xsl:when>
           <xsl:otherwise>
<xsl:value-of select="$locals/lookup/words/word[(_at_)physical=$substring]/@logical"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:when>
<xsl:when test="$locals/lookup/words/word[(_at_)shortPhysical=$substring]">
         <xsl:choose>
<xsl:when test="$locals/lookup/words/word[(_at_)shortPhysical=$substring and @logical='*']">
             <xsl:value-of select="$substring"/>
           </xsl:when>
           <xsl:otherwise>
<xsl:value-of select="$locals/lookup/words/word[(_at_)shortPhysical=$substring]/@logical"/>
           </xsl:otherwise>
         </xsl:choose>
       </xsl:when>
       <xsl:otherwise>
<xsl:value-of select="concat(substring(., 1, 1), lower-case(substring(., 2)))"/>
       </xsl:otherwise>
     </xsl:choose>
   </xsl:non-matching-substring>
 </xsl:analyze-string>
</xsl:function>

The $locals document contains reserved words that have special conversion rules, like this:

<?xml version="1.0"?>
<lookup>
   <words>
<word physical="ACCT" shortPhysical="*" comment="*" logical="Account"/>
...
       <word physical="ZIP" shortPhysical="*" comment="*" logical="*"/>
   </words>
</lookup>

What I would like it to do is convert

ACCOUNT_TO_GROUP

into

AccountToGroup

via <xsl:value-of select="local:logicalName(@name)"/> but instead it is putting spaces between the words. I understand that xsl:function is defined to return a sequence which is what I guess is going on here. I can use string-join to squish them back together, but is there a way to output the desired result from the function directly?

Thanks,
Barry


<Prev in Thread] Current Thread [Next in Thread>