W3C home > Mailing lists > Public > public-powderwg@w3.org > May 2009

Re: more struggles with POWDER test materials

From: Cameron McCormack <cam@mcc.id.au>
Date: Fri, 15 May 2009 16:47:27 +1000
To: Phil Archer <phil@philarcher.org>
Cc: Harry Halpin <hhalpin@ibiblio.org>, Dan Connolly <connolly@w3.org>, public-powderwg <public-powderwg@w3.org>, www-tag@w3.org
Message-ID: <20090515064727.GJ11882@arc.mcc.id.au>
Phil Archer:
> We need the replace() function in XSLT 2 to convert our white space  
> separated lists into regular expressions. In simplified form, something 
> like
> <includehsosts>example.com example.org</includehosts>
> becomes
> <includeregex>[regex_blurb] (example.com|example.org) [more_regex_blurb]  
> </includeregex>
> And (our XML expert reliably informs me) you can't do that in XSLT 1.

You can, it just takes a bit of extra work:

zot:/tmp $ cat b.xsl; echo
<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
  <xsl:template match='includehosts'>
      <xsl:text>[regex_blurb] (</xsl:text>
      <xsl:call-template name='replace-space-with-bar'>
        <xsl:with-param name='s' select='.'/>
      <xsl:text>) [regex_blurb]</xsl:text>

  <xsl:template name='replace-space-with-bar'>
    <xsl:param name='s'/>
      <xsl:when test='contains($s, " ")'>
        <xsl:value-of select='substring-before($s, " ")'/>
        <xsl:call-template name='replace-space-with-bar'>
          <xsl:with-param name='s' select='substring-after($s, " ")'/>
      <xsl:otherwise><xsl:value-of select='$s'/></xsl:otherwise>

zot:/tmp $ cat b.xml; echo
<includehosts>example.com example.org</includehosts>

zot:/tmp $ xsltproc b.xsl b.xml
<?xml version="1.0"?>
<includeregex>[regex_blurb] (example.com|example.org) [regex_blurb]</includeregex>

Cameron McCormack ≝ http://mcc.id.au/
Received on Friday, 15 May 2009 06:48:29 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 7 December 2009 10:42:14 GMT