Re: [xsl] tokenizing comma separated string with quotes

Subject: Re: [xsl] tokenizing comma separated string with quotes
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Thu, 22 Feb 2007 10:04:16 +0000
On 2/21/07, Houghton,Andrew <houghtoa@xxxxxxxx> wrote:
> From: Andrew Welch [mailto:andrew.j.welch@xxxxxxxxx]
> Sent: 21 February, 2007 14:07
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] tokenizing comma separated string with quotes
> Given the input
> <elem>"foo, bar", baz, bom</elem>
> Is there a nice one liner  / technique to return the three
> tokens "foo, bar"  "baz" "bom"
> eg:
> <root>
>   <token>foo, bar</token>
>   <token>baz</token>
>   <token>bom</token>
> </root>
> I can't see the answer for all the apparent quote escaping required...

If you are using XSL 2.0, this should work:

Input file: <elem>"foo, bar", baz, bom</elem>

Transform file: <xsl:transform version="2.0" exclude-result-prefixes="xsd xsi xsl"



  <xsl:output method="xml" version="1.0"
    media-type="text/xml" encoding="utf-8"
    omit-xml-declaration="yes" indent="yes"

  <xsl:variable name="regex">

  <xsl:template match="/">
      <xsl:analyze-string regex="{$regex}" select="/elem">
          <token><xsl:value-of select="regex-group(1)"/></token>


Output file: <root> <token>"foo, bar"</token> <token>baz</token> <token>bom</token> </root>

Thanks Andrew - is there a modification to the regex to not include
the surrounding quotes?


<token>"foo, bar"</token>

should be

<token>foo, bar</token>

I can translate away the quotes, but it would be nice if the regex
could be modified to do the same thing.

Current Thread