Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XPATH2.0 fn:matches() can somebody confirm if my understanding is OK

Reply
Thread Tools

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

 
 
RolfK
Guest
Posts: n/a
 
      12-18-2007
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 xmlnssl="http://www.w3.org/1999/XSL/Transform"
version="2.0" xmlns:fn="http://www.w3.org/2005/xpath-functions">
<xslutput 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>
<xsltherwise>
<item Value="{.}" Type="ERROR"/>
</xsltherwise>
</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>
############################

 
Reply With Quote
 
 
 
 
Martin Honnen
Guest
Posts: n/a
 
      12-18-2007
RolfK wrote:

> 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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
 
Pavel Lepin
Guest
Posts: n/a
 
      12-18-2007

RolfK <(E-Mail Removed)> wrote in
<(E-Mail Removed)>:
> 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.

--
....also, I submit that we all must honourably commit seppuku
right now rather than serve the Dark Side by producing the
HTML 5 spec.
 
Reply With Quote
 
RolfK
Guest
Posts: n/a
 
      12-18-2007
On 18 Dez., 15:03, Martin Honnen <(E-Mail Removed)> wrote:
> RolfK wrote:
> > 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.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


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

Thanks
Rolf
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-18-2007
RolfK wrote:

> 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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
RolfK
Guest
Posts: n/a
 
      12-18-2007
On 18 Dez., 15:09, Pavel Lepin <(E-Mail Removed)> wrote:
> RolfK <(E-Mail Removed)> wrote in
> <(E-Mail Removed)>:
>
> > 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.
>
> --
> ...also, I submit that we all must honourably commit seppuku
> right now rather than serve the Dark Side by producing the
> HTML 5 spec.


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
 
Reply With Quote
 
RolfK
Guest
Posts: n/a
 
      12-18-2007
On 18 Dez., 16:57, Martin Honnen <(E-Mail Removed)> wrote:
> RolfK wrote:
> > 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.
>
> --
>
> Martin Honnen
> http://JavaScript.FAQTs.com/


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
 
Reply With Quote
 
Martin Honnen
Guest
Posts: n/a
 
      12-18-2007
RolfK wrote:

> 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.


--

Martin Honnen
http://JavaScript.FAQTs.com/
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert, Update and Delete. Can somebody please help me? Shapper ASP .Net 3 07-09-2005 04:43 AM
Confirm my wireless understanding please? Evil Uncle Chris Wireless Networking 1 05-01-2005 03:19 PM
can somebody guide me through this step by step? Taquin Noel Wireless Networking 5 12-26-2004 01:31 AM
XML String Manipulation <--- Have somebody can help me? dd711 Java 6 10-01-2004 01:49 PM
How can I let somebody print only one copy of something? BruceJ HTML 3 09-20-2003 02:11 AM



Advertisments