Saturday, October 07, 2017

Splitting a string using XSLT 2.0

The tokenize function available in XSL Transformations (XSLT) Version 2.0 allows you to split a string on any separator that matches a given regular expression.

The example below shows how you can split a comma-delimited string:

Input XML:


XSL 2.0 Stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="">
  <xsl:template match="data">
      <xsl:variable name="stringToSplit" select="stringToSplit" />
      <xsl:for-each select="tokenize($stringToSplit, ',')">
          <xsl:value-of select="." />

Output XML:

<?xml version="1.0" encoding="UTF-8"?>

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.