XPATH2.0 fn:matches() can somebody confirm if my understanding is OK

RolfK

Usenet Archive
Joined
Dec 17, 2007
Messages
34
Reaction score
0
Dear ALL,

I'm writing some first examples to get a better understanding of XSLT/ XPATH2.0. Please excute this code, any xml input is OK. I'm using saxon. The example runs perfect with ALTOVA, but fails with SAXON.

Please refere to line with element <matches> which is quite close to the error.

Error at choose on line 26 of file:/.....:
No function found matching fn:matches with 2 arguments
Transformation failed: Run-time errors were reported

Any idea ?

Any comments on the rest of the example are very welcome ! (I'm just started to dig into XSLT2.0 stub)

################ xslt #######################
<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xmlns:fn="http://www.w3.org/2005/xpath-functions"> <xsl:eek:utput method="xml" indent="yes"/> <xsl:template match="/"> <output> <analyze> <xsl:analyze-string select="'@abcd[123]'" regex="(@|#)?(\w+)\[(\d+) \]"> <xsl:matching-substring> <m group="1"> <xsl:value-of select="regex-group(1)"/> </m> <m group="2"> <xsl:value-of select="regex-group(2)"/> </m> <m group="3"> <xsl:value-of select="regex-group(3)"/> </m> </xsl:matching-substring> <xsl:non-matching-substring> <xsl:value-of select="."/> </xsl:non-matching-substring> </xsl:analyze-string> </analyze> <functions> <xsl:for-each select="('@param[2]','#define','0','H','L','invalid','##','@@','HL')"> <matches> <xsl:choose> <xsl:when test="fn:matches(.,'^@\w+\[\d+\]$')"> <item Value="{.}" Type="Parameter"/> </xsl:when> <xsl:when test="fn:matches(.,'^#\w+$')"> <item Value="{.}" Type="Define"/> </xsl:when> <xsl:when test="fn:matches(.,'^[01ZHLX]{1}$')"> <item Value="{.}" Type="Value"/> </xsl:when> <xsl:eek:therwise> <item Value="{.}" Type="ERROR"/> </xsl:eek:therwise> </xsl:choose> </matches> <tokenize> <xsl:variable name="vTokens" select="fn:tokenize(.,'(@)|(#)|(\[)| (\])')"/> <tokens count="{count($vTokens)}"> <xsl:for-each select="$vTokens"> <token value="{.}"/> </xsl:for-each> </tokens> </tokenize> </xsl:for-each> </functions> </output> </xsl:template> </xsl:transform> ############################
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
RolfK said:
I'm writing some first examples to get a better understanding of XSLT/ XPATH2.0. Please excute this code, any xml input is OK. I'm using saxon. The example runs perfect with ALTOVA, but fails with SAXON.

Please refere to line with element <matches> which is quite close to the error.

Error at choose on line 26 of file:/.....:
No function found matching fn:matches with 2 arguments
Transformation failed: Run-time errors were reported

Any idea ?

I have tried your stylesheet with Saxon 9 and run it against itself as the input document, it does not give any error. Which version of Saxon are you using?

Also note that the XSLT/XPath functions can be accessed without using a prefix so you don't need fn:matches, simply doing matches should work.
 

Pavel Lepin

Usenet Archive
Joined
Apr 20, 2007
Messages
263
Reaction score
0
RolfK said:
Please excute this code, any xml input is OK.
I'm using saxon. The example runs perfect with ALTOVA, but fails with SAXON.

Please refere to line with element <matches> which is
quite close to the error.

Error at choose on line 26 of file:/.....:
No function found matching fn:matches with 2 arguments
Transformation failed: Run-time errors were reported

pavel@debian:~/dev/xslt$ saxon -t matches.xsl matches.xsl Saxon 8.8J from Saxonica Java version 1.5.0 Stylesheet compilation time: 767 milliseconds
Processing file:/var/www/dev/xslt/matches.xsl
Building tree for file:/var/www/dev/xslt/matches.xsl using class net.sf.saxon.tinytree.TinyBuilder Tree built in 28 milliseconds
Tree size: 86 nodes, 0 characters, 30 attributes
<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:fn="http://www.w3.org/2005/xpath-functions"> <analyze> <m group="1">@</m> <m group="2">abcd</m> <m group="3">123</m> </analyze> <functions> <matches> <item Value="@param[2]" Type="Parameter"/> </matches> <tokenize> <tokens count="2"> <token value="@param[2"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="#define" Type="Define"/> </matches> <tokenize> <tokens count="1"> <token value="#define"/> </tokens> </tokenize> <matches> <item Value="0" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="0"/> </tokens> </tokenize> <matches> <item Value="H" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="H"/> </tokens> </tokenize> <matches> <item Value="L" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="L"/> </tokens> </tokenize> <matches> <item Value="invalid" Type="ERROR"/> </matches> <tokenize> <tokens count="1"> <token value="invalid"/> </tokens> </tokenize> <matches> <item Value="##" Type="ERROR"/> </matches> <tokenize> <tokens count="2"> <token value="#"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="@@" Type="ERROR"/> </matches> <tokenize> <tokens count="2"> <token value="@"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="HL" Type="ERROR"/> </matches> <tokenize> <tokens count="1"> <token value="HL"/> </tokens> </tokenize> </functions> </output>Execution time: 212 milliseconds
Memory used: 12115968
NamePool contents: 33 entries in 30 chains. 8 prefixes, 8 URIs pavel@debian:~/dev/xslt$
Any comments on the rest of the example are very welcome !

Right. Parsing a few dozen lines of XSLT2, formatted with tabs, with no respect for 78 chars rule, AND with some regexen thrown in as an added bonus, *AND* without having the slightest idea what the hell it is supposed to do somehow doesn't fit my idea of fun.
 

RolfK

Usenet Archive
Joined
Dec 17, 2007
Messages
34
Reaction score
0
I have tried your stylesheet with Saxon 9 and run it against itself as the input document, it does not give any error. Which version of Saxon are you using?

Also note that the XSLT/XPath functions can be accessed without using a prefix so you don't need fn:matches, simply doing matches should work.

Martin,
thank you very much for taking care.
I'm running the non comercial version 8.0.
Any recommendation to change ?

Thanks
Rolf
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
RolfK said:
I'm running the non comercial version 8.0.
Any recommendation to change ?

As far as I know 8.9 is the first release to implement the XSLT/XPath
2.0 standard released the beginning of 2007 so I would not bother with
8.0. And 9.0 is the current release thus if you download a new version I would directly choose the latest version 9 from <URL:http://saxon.sourceforge.net/>

The namespace for XPath functions was changed during the development of the XSLT and XPath standards so that is probably why your attempt with version 8 fails.
 

RolfK

Usenet Archive
Joined
Dec 17, 2007
Messages
34
Reaction score
0
Please excute this code, any xml input is OK.
I'm using saxon. The example runs perfect with ALTOVA, but fails with SAXON.
Please refere to line with element <matches> which is
quite close to the error.
Error at choose on line 26 of file:/.....:
No function found matching fn:matches with 2 arguments
Transformation failed: Run-time errors were reported

pavel@debian:~/dev/xslt$ saxon -t matches.xsl matches.xsl Saxon 8.8J from Saxonica Java version 1.5.0 Stylesheet compilation time: 767 milliseconds
Processing file:/var/www/dev/xslt/matches.xsl
Building tree for file:/var/www/dev/xslt/matches.xsl using class net.sf.saxon.tinytree.TinyBuilder Tree built in 28 milliseconds
Tree size: 86 nodes, 0 characters, 30 attributes
<?xml version="1.0" encoding="UTF-8"?>
<output xmlns:fn="http://www.w3.org/2005/xpath-functions"> <analyze> <m group="1">@</m> <m group="2">abcd</m> <m group="3">123</m> </analyze> <functions> <matches> <item Value="@param[2]" Type="Parameter"/> </matches> <tokenize> <tokens count="2"> <token value="@param[2"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="#define" Type="Define"/> </matches> <tokenize> <tokens count="1"> <token value="#define"/> </tokens> </tokenize> <matches> <item Value="0" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="0"/> </tokens> </tokenize> <matches> <item Value="H" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="H"/> </tokens> </tokenize> <matches> <item Value="L" Type="Value"/> </matches> <tokenize> <tokens count="1"> <token value="L"/> </tokens> </tokenize> <matches> <item Value="invalid" Type="ERROR"/> </matches> <tokenize> <tokens count="1"> <token value="invalid"/> </tokens> </tokenize> <matches> <item Value="##" Type="ERROR"/> </matches> <tokenize> <tokens count="2"> <token value="#"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="@@" Type="ERROR"/> </matches> <tokenize> <tokens count="2"> <token value="@"/> <token value=""/> </tokens> </tokenize> <matches> <item Value="HL" Type="ERROR"/> </matches> <tokenize> <tokens count="1"> <token value="HL"/> </tokens> </tokenize> </functions> </output>Execution time: 212 milliseconds
Memory used: 12115968
NamePool contents: 33 entries in 30 chains. 8 prefixes, 8 URIs pavel@debian:~/dev/xslt$
Any comments on the rest of the example are very welcome !

Right. Parsing a few dozen lines of XSLT2, formatted with tabs, with no respect for 78 chars rule, AND with some regexen thrown in as an added bonus, *AND* without having the slightest idea what the hell it is supposed to do somehow doesn't fit my idea of fun.

Pavel,
thank you for the answer and running the code. As you and others could excute it , It shows that I have most probably a saxon version problem. Concerning your input on 78chars rule, how do you create such messages ? Usually I'm working with Altova and its pretty print. And hate everything is warpped (makes it unreadable for me). At all I do not want to annoy the community. So how to make it better ?

Thanks
Rolf
 

RolfK

Usenet Archive
Joined
Dec 17, 2007
Messages
34
Reaction score
0
As far as I know 8.9 is the first release to implement the XSLT/XPath
2.0 standard released the beginning of 2007 so I would not bother with
8.0. And 9.0 is the current release thus if you download a new version I would directly choose the latest version 9 from <URL:http://saxon.sourceforge.net/>

The namespace for XPath functions was changed during the development of the XSLT and XPath standards so that is probably why your attempt with version 8 fails.

Martin, thanks a lot for quick reply.
I used the name space found in the W3C recommendation for XPATH chater
1.2
Which shows this:
The URIs of the namespaces and the default prefixes associated with them are:

http://www.w3.org/2001/XMLSchema for constructors -- associated with xs.

http://www.w3.org/2005/xpath-functions for functions -- associated with fn.

http://www.w3.org/2005/xqt-errors -- associated with err.

Is this already old / wrong ?

Rolf
 

Martin Honnen

Usenet Archive
Joined
Apr 8, 2000
Messages
6,174
Reaction score
0
RolfK said:
I used the name space found in the W3C recommendation for XPATH chater
1.2
Which shows this:
The URIs of the namespaces and the default prefixes associated with them are:

http://www.w3.org/2001/XMLSchema for constructors -- associated with xs.

http://www.w3.org/2005/xpath-functions for functions -- associated with fn.

http://www.w3.org/2005/xqt-errors -- associated with err.

Is this already old / wrong ?

Your version of Saxon is old and probably implements a different namespace from the one finalized later. What prevents you from updating your Saxon to the latest version?

And as already said, you do not need a namespace/prefix at all to access the predefined XPath functions.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
548,050
Messages
3,104,249
Members
248,133
Latest member
DujonT

Latest Threads

Top