Previous | Next | Indexes
Zvon > Tutorials > XSLT 2.0 Tutorial > Transforming strings with regular expressions (6/8) >

Creating text nodes by regular expressions - function tokenize()

Function tokenize() creates text nodes from a string submitted as the first argument. The second argument is a pattern which specifies separator between individual substrings. The separators are not returned.

XSLT

      <xsl:stylesheet
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                  version="2.0">
            <xsl:output  method="xml"
                        indent="yes"
                        omit-xml-declaration="yes"/>

            <xsl:template  match="/aaa">
                  <ul>
                        <xsl:for-each  select="tokenize(.,'\s+')">
                              <li>
                                    <xsl:value-of  select="."/>
                              </li>
                        </xsl:for-each>
                  </ul>
            </xsl:template>

      </xsl:stylesheet>
XML

      <aaa>How do you do</aaa>
Output

      <ul>
            <li>How</li>
            <li>do</li>
            <li>you</li>
            <li>do</li>
      </ul>


Previous chapter: Functions operating on strings
Next chapter: Number Formatting
Previous page: Escaping special characters
Next page: Creation of text nodes from a string with regular expressions - function analyze-string