[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Algorithm for splitting a string at a space


Subject: Re: [xsl] Algorithm for splitting a string at a space
From: "David Carlisle d.p.carlisle@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 23 Nov 2015 19:17:44 -0000

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

 <xsl:output omit-xml-declaration="yes" indent="yes"/>

 <xsl:template name="m">
  <xsl:analyze-string select="'This is a long line that I want to
split at a space. '"
              regex=".{{0,30}}( )">
   <xsl:matching-substring>
    <x><xsl:value-of select="replace(.,' $','')"/></x>
   </xsl:matching-substring>
   <xsl:non-matching-substring>
    <y><xsl:value-of select="."/></y>
   </xsl:non-matching-substring>
  </xsl:analyze-string>
 </xsl:template>
</xsl:stylesheet>


produces

<x>This is a long line that I</x>
<x>want to split at a space.</x>

David


Current Thread