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

Creation of text nodes from a string with a regular expression separator

If element xsl:non-matching-substring is used instead of xsl:matching-substring inside xsl:analyze-string, the regular expression in regex specifies a separator which splits the input string into several parts. From each of these parts a text node is created, the separators are discarded.

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">
                  <xsl:analyze-string  select="bbb"
                              regex="\s">
                        <xsl:non-matching-substring>
                              <aaa>
                                    <xsl:value-of  select="."/>
                              </aaa>
                        </xsl:non-matching-substring>
                  </xsl:analyze-string>
            </xsl:template>

      </xsl:stylesheet>
XML

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

      <aaa>How</aaa>
      <aaa>do</aaa>
      <aaa>you</aaa>
      <aaa>do?</aaa>


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