xsl-list
[Top] [All Lists]

RE: Splitting an +attribute+ string

2005-01-13 04:24:37

I wonder if anybody could quickly profer some advice on this.
I may well be wrong, but does xsl treat attribute strings 
different to 
normal text nodes when it comes to the "contains()" function. 
I may well 
also be gibbering. I've got my mind into a muddle on this one.

Problem :  To take an attribute in the form of a comma 
delineated string 
(e.g. <gui onShow="apple,pear,banana" 
onHide="black,white,grey"/>) and 
to covert the attributes into javascript array syntax (i.e. 
['apple','pear','banana'] etc.).

Strategy : "Just" replace the commas with ',' and top and tail the 
output string with [' and ']

Code  :
<!--To convert onShow-->
<xsl:call-template name="commaDelineate"><xsl:with-param name="str" 
select="@onShow"/></xsl:call-template>

<xsl:template name="commaDelineate">
 <xsl:param name="str"/>
    <xsl:when test="contains($str,',')">
      <xsl:value-of select="substring-before($str,',')"/>','
      <xsl:call-template name="commaDelineate">
        <xsl:with-param name="str" 
select="substring-after($str,',')"/>
      </xsl:call-template>
    </xsl:when>
</xsl:template>

Frustration : The errors seem to be generated around the "when" 
statement. Unfortunately I can't  provide any error output 
because this 
is being done inside a PHP script.

You are missing <xsl:choose> and also:

<xsl:otherwise>
        <xsl:value-of select="$str"/>
</xsl:otherwise>

to get the last part of the string?

Don't kick yourself too hard :)

cheers
andrew

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



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