I know there are existing tokenizing functions,
however, I keep getting weird results with Xalan ? so
to continue with the project, I wrote a template based
on the EXSLT template to separate a string into
separate tokens. This is somewhat simplified from the
EXSLT version, because there is only 1 delimiter
character. Seemed fairly simple, as I?ve worked with
recursive templates before.
But, I?ve stared at this for hours, tested the input
at different rounds of recursion and am still getting
weird results. Hopefully someone else can see the
undoubtedly stupid mistake that I?ve made.
With an input string of ?input/xml/../? and a
delimiter of ?/? and this template:
<xsl:template name="tokenize.path">
<xsl:param name="string" select="''"/>
<xsl:param name="delimiter" select="' '"/>
<xsl:variable name="normal.string"
select="normalize-space($string)"/>
<xsl:choose>
<xsl:when test="contains($normal.string,
$delimiter)">
<xsl:choose>
<xsl:when test="starts-with($normal.string,
$delimiter)">
<xsl:call-template name="tokenize.path">
<xsl:with-param name="string"
select="substring($normal.string, 2)" />
<xsl:with-param name="delimiter"
select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:when
test="substring($normal.string,string-length($normal.string))
= $delimiter">
<xsl:call-template name="tokenize.path">
<xsl:with-param name="string"
select="substring($normal.string,1,string-length($normal.string)-1)"
/>
<xsl:with-param name="delimiter"
select="$delimiter" />
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<token><xsl:value-of
select="substring-before($normal.string,
$delimiter)"/></token>
<xsl:call-template name="tokenize.path">
<xsl:with-param name="string"
select="substring-after($normal.string, $delimiter)"
/>
<xsl:with-param name="delimiter"
select="$delimiter" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:when>
<xsl:when test="$string">
<token><xsl:value-of
select="$normal.string"/></token>
</xsl:when>
</xsl:choose>
</xsl:template>
I get back:
<token>input</token>
<token>xml</token>
<token>.. input/</token>
I?ve narrowed it down to the ?when test=?$string??
clause but still can?t figure out why the extra
?input/? is showing up. <head-bang/>.
Any help would be appreciated.
Sara Mitchell
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
--~------------------------------------------------------------------
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>
--~--