[xsl] regex in XSLT 2.0: problems with XPath

Subject: [xsl] regex in XSLT 2.0: problems with XPath
From: Manuel Souto Pico <manuel.souto@xxxxxxxxxxxxxx>
Date: Fri, 13 Feb 2009 17:23:11 +0100
Hi again,

I was glad to find out that XSLT 2.0 supports regular expressions (although I was surprised they weren't supported already in 1.0). I'm trying to use them to capture some element if its contents match some expression.

It seems that I need to use XSLT 2.0, so I believe I must change the definition in the XSLT document (see 2nd line in the preamble of my doc just below) as well as the processor version (I used Saxon 6.5.5. with XSLT 1.0, now I've chosen Saxon-SA 9.1.0.3). I do all of this in oXygen 10 and I haven't done anything else to use XSLT 2.0.

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />
(...)


The area of code where I want to use regular expressions look like (using the syntax matches(elem, expr):

<xsl:for-each select="../category[@domain='tag'][@nicename]">
<xsl:if test="matches(../category[@domain='tag'][@nicename], &lt;!\[CDATA\[economia\]\]&gt;)">
<descrip type='subjectfield'>
<xsl:value-of select="../category[@domain='tag'][@nicename]"/>
</descrip> </xsl:if> </xsl:for-each>


However, when I run the debugger, I get this error message:

   SystemID: vds2tbx.xsl
   Description: Failed to compile stylesheet. 1 error detected.

   SystemID: vds2tbx.xsl
   Location: 37:0
   Description: XPath syntax error at char 47 on line 37 in
   {...y[@domain='tag'][@nicename]...}:
       Node constructor expressions are allowed only in XQuery, not in
   XPath
   URL: http://www.w3.org/TR/xpath20/#ERRXPST0003

Googling that error I couldn't find any useful pages, so I am quite stuck. What am I doing wrong? Am I using the old version of XPath?

I hope my questions are interesting for the list!
Regards, Manuel

--
Manuel Souto Pico
Terminslogo / Responsable de servicio ticnico

*STAR Servicios Ling|msticos, SL*
C. Sardenya, 195-197 (baixos)
E-08013 Barcelona
Tel. +34 932 440 881
Fax: +34 932 471 273

manuel.souto@xxxxxxxxxxxxxx <mailto:manuel.souto@xxxxxxxxxxxxxx>
http://www.star-spain.com

Current Thread