Re: [xsl] Substrings

Subject: Re: [xsl] Substrings
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Tue, 31 May 2005 06:49:28 +1000
On 5/31/05, Karl Stubsjoen <kstubs@xxxxxxxxx> wrote:
> To "tokenize" is that to say I am going to split the string up by
> spaces, or other delimiters?  So then, I could recursively call a
> template which returns a value of nothing but passes back the
> substring value of supplied string after each space until which time I
> find an @ at this point I stop recursing and pass back the value.  (i
> think that makes sense, and I think I can write that!)
>
> I am using XSLT 1 with microsoft's msxml parser so exslt is not available to
me.

Using FXSL (for MSXML), one would write something like this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:vendor="urn:schemas-microsoft-com:xslt"
 exclude-result-prefixes="vendor"
 >

 <xsl:import href="strSplit-to-Words.xsl"/>

 <!-- To be applied on: testSplitToWords10.xml -->
 <xsl:output omit-xml-declaration="yes" />

  <xsl:template match="/">
    <xsl:variable name="vrtfWords">
      <xsl:call-template name="str-split-to-words">
        <xsl:with-param name="pStr" select="/*"/>
        <xsl:with-param name="pDelimiters" select="' ,.;&#9;&#10;'"/>
      </xsl:call-template>
    </xsl:variable>

    <xsl:copy-of select=
    "vendor:node-set($vrtfWords)/word
              [contains(., '@')]"/>
  </xsl:template>

</xsl:stylesheet>

When this transformation is applied on this source.xml:

<t>
   Mr. Joseph Smith Jr. III jsmithjr@xxxxxxxx "J Jr."
</t>


the wanted result is produced:

    <word>jsmithjr@juno</word>


Hope this helped.


Cheers,
Dimitre Novatchev

Current Thread