- From: Smith, Kevin, (R&D) VF-Group <Kevin.Smith@vodafone.com>
- Date: Fri, 15 May 2009 10:03:21 +0200
- To: <cam@mcc.id.au>, <phil@philarcher.org>
- Cc: <hhalpin@ibiblio.org>, <connolly@w3.org>, <public-powderwg@w3.org>, <www-tag@w3.org>
Hi Cameron, Thanks for the snippet, which solves the problem as stated: however there was more to the problem than that: namely we need to regex-escape the string (not just deal with spaces). There may be a way to recurse on the string to achieve this: identify a segment before any of the regex reserved characters, concat() the escape, recurse until complete; but the problem there is that the escaped string still contains the reserved character. XSLT 1's translate() function can only cope with the translation of one character into another so that doesn't help us. I wouldn't be surprised if one of the XSLT 1 gurus could find a heavyweight multi-template way around this; however it is exactly the sort of problem that replace() was introduced to deal with in XSLT 2. Any suggestions gratefully received but not something I will have time to change at the moment - my assumption was that XSLT 2 was an approved recommendation and hence appropriate for the task. Cheers, Kevin Kevin Smith Vodafone R&D ----- Original Message ----- From: public-powderwg-request@w3.org <public-powderwg-request@w3.org> 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 <www-tag@w3.org> Sent: Fri May 15 08:47:27 2009 Subject: 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>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' version='1.0'> <xsl:template match='includehosts'> <includeregex> <xsl:text>[regex_blurb] (</xsl:text> <xsl:call-template name='replace-space-with-bar'> <xsl:with-param name='s' select='.'/> </xsl:call-template> <xsl:text>) [regex_blurb]</xsl:text> </includeregex> </xsl:template> <xsl:template name='replace-space-with-bar'> <xsl:param name='s'/> <xsl:choose> <xsl:when test='contains($s, " ")'> <xsl:value-of select='substring-before($s, " ")'/> <xsl:text>|</xsl:text> <xsl:call-template name='replace-space-with-bar'> <xsl:with-param name='s' select='substring-after($s, " ")'/> </xsl:call-template> </xsl:when> <xsl:otherwise><xsl:value-of select='$s'/></xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> 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 08:04:21 UTC