xsl-list
[Top] [All Lists]

RE: [xsl] regex in XSLT 2.0: problems with XPath

2009-02-13 11:41:21
The XPath parser has seen an expression beginning with "<". There are no
expressions beginning with this character in XPath, only in XQuery, hence
the error message.

Your regular expression needs to be in quotes, for example <xsl:if
test="matches($x, '&lt;\[')">

Michael Kay
http://www.saxonica.com/

 

-----Original Message-----
From: Manuel Souto Pico [mailto:manuel(_dot_)souto(_at_)star-group(_dot_)net] 
Sent: 13 February 2009 16:23
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] regex in XSLT 2.0: problems with XPath

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[(_at_)domain='tag'][(_at_)nicename]">
                                    <xsl:if 
test="matches(../category[(_at_)domain='tag'][(_at_)nicename],
&lt;!\[CDATA\[economia\]\]&gt;)">
                                        <descrip type='subjectfield'>
                                            <xsl:value-of 
select="../category[(_at_)domain='tag'][(_at_)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
    
{(_dot_)(_dot_)(_dot_)y[(_at_)domain='tag'][(_at_)nicename](_dot_)(_dot_)(_dot_)}:
        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
Terminólogo / Responsable de servicio técnico

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

manuel(_dot_)souto(_at_)star-group(_dot_)net 
<mailto:manuel(_dot_)souto(_at_)star-group(_dot_)net>
http://www.star-spain.com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>