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

Discussion in 'XML' started by RolfK, Dec 18, 2007.

  1. RolfK

    RolfK Guest

    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>
    ############################
     
    RolfK, Dec 18, 2007
    #1
    1. Advertising

  2. Re: XPATH2.0 fn:matches() can somebody confirm if my understandingis OK

    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 Honnen, Dec 18, 2007
    #2
    1. Advertising

  3. RolfK

    Pavel Lepin Guest

    RolfK <> wrote in
    <>:
    > 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 Lepin, Dec 18, 2007
    #3
  4. RolfK

    RolfK Guest

    Re: XPATH2.0 fn:matches() can somebody confirm if my understanding isOK

    On 18 Dez., 15:03, Martin Honnen <> 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
     
    RolfK, Dec 18, 2007
    #4
  5. Re: XPATH2.0 fn:matches() can somebody confirm if my understandingis OK

    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 Honnen, Dec 18, 2007
    #5
  6. RolfK

    RolfK Guest

    Re: XPATH2.0 fn:matches() can somebody confirm if my understanding isOK

    On 18 Dez., 15:09, Pavel Lepin <> wrote:
    > RolfK <> wrote in
    > <>:
    >
    > > 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
     
    RolfK, Dec 18, 2007
    #6
  7. RolfK

    RolfK Guest

    Re: XPATH2.0 fn:matches() can somebody confirm if my understanding isOK

    On 18 Dez., 16:57, Martin Honnen <> 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
     
    RolfK, Dec 18, 2007
    #7
  8. Re: XPATH2.0 fn:matches() can somebody confirm if my understandingis OK

    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/
     
    Martin Honnen, Dec 18, 2007
    #8
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Shapper
    Replies:
    3
    Views:
    573
    Scott Allen
    Jul 9, 2005
  2. Replies:
    1
    Views:
    1,751
    Martin Honnen
    Oct 5, 2005
  3. Christof Hoeke

    state of XSLT2/XPath2 or XQuery in CPython

    Christof Hoeke, Dec 26, 2007, in forum: Python
    Replies:
    2
    Views:
    333
    Christof Hoeke
    Dec 26, 2007
  4. Philippe Poulard

    Typed datas in XPath2

    Philippe Poulard, Jan 9, 2008, in forum: XML
    Replies:
    2
    Views:
    356
    Philippe Poulard
    Jan 9, 2008
  5. Ian Clifton

    "." versus ".." in XPath2.0

    Ian Clifton, Dec 2, 2010, in forum: XML
    Replies:
    9
    Views:
    1,107
    Martin Honnen
    Dec 11, 2010
Loading...

Share This Page