[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

separating token problems

Subject: separating token problems
From: Sara Mitchell <samitchell6@xxxxxxxxx>
Date: Wed, 14 Jun 2006 14:48:58 -0700 (PDT)
string token
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 Ive worked with
recursive templates before. 

But, Ive 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 Ive 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> 

Ive narrowed it down to the when test=$string
clause but still cant 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 

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.