Re: more struggles with POWDER test materials

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></includehosts>
> becomes
> <includeregex>[regex_blurb] (| [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=''
  <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

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

Cameron McCormack ≝

Received on Friday, 15 May 2009 06:48:28 UTC