In article <d9*************************@posting.google.com> ,
Edwin G. Castro <ec*****@hp.com> wrote:
% I have a XML file with a whole bunch of <message> elements. These
% <message> elements have <![CDATA[...]]> in them. I would like to use
% XSLT to remove the <message> elements whose CDATA (the "...") matches
% a particular regular expression.
XSLT can't detect the CDATA sections as such. They're just (parts of) text
nodes so far as XPath and XSLT are concerned. Assuming that's not
a problem, you run into the problem that XSLT 1.0 doesn't provide any
regular expression support.
When you run into a basic limitation like that, scoot over to
http://exslt.org and see what's being proposed there. In this
case, you'll find a little number they like to call
http://exslt.org/regular-expressions, which can be used like this
<xsl:stylesheet xmlns:xsl = 'http://www.w3.org/1999/XSL/Transform'
version = '1.0'
xmlns:re = 'http://exslt.org/regular-expressions'>
<xsl:template match='node()|@*'>
<xsl:copy>
<xsl:apply-templates select='node()|@*'/>
</xsl:copy>
</xsl:template>
<!-- ignore messages dated in the first two months of the year -->
<xsl:template match = 'message[re:test(string(.),
"(Janvier|Fevrier) 200[34]")]'/>
</xsl:stylesheet>
This interface is marked experimental, so it might not work with your
XSLT processor, even if it supports the EXSLT extensions. Also, some
processors require you to have extension-element-prefixes='re' on
the stylesheet element, but I believe they shouldn't.
If that doesn't work for you, you could see if there are other
extension functions or language interfaces available to you. On
the other hand, if all you want to do is drop out elements whose
content matches an RE, this may be a job for another language.
--
Patrick TJ McPhee
East York Canada
pt**@interlog.com