Gerrit! You wound me - I'm cut to the very core :)
For the life of me, I couldn't remember if the `fn` prefix was correct or not. @Ben - Gerrit's absolutely right - wildcards are desperate measures (or for quick, one-off scripts). Using the namespace is much preferable. Best, Bridger On Thu, Feb 10, 2022, 12:46 PM Imsieke, Gerrit, le-tex < gerrit.imsi...@le-tex.de> wrote: > It’s a namespace thing. The analyze-string() result is in the > http://www.w3.org/2005/xpath-functions namespace, which is bound to the > fn prefix. So you should write fn:match etc. instead of match, or, as > Bridger suggested, *:match. But such a wildcard always seems a bit > desperate to me (no offense, Bridger ;). > Whereas you don’t need to use the privileged fn prefix when you invoke > analyze-string(), it’s only important when you select the namespaced > results. > > Gerrit > > On 10.02.2022 18:30, Ben Engbers wrote: > > Hi, > > > > This query produces the following result: > > > > let $debates := collection("Parliament") > > for $debate-item in $debates > > let $item-file := $debate-item/officiele-publicatie//meta/@content > > let $debate-id := fn:analyze-string( > > $debate-item/officiele-publicatie//meta/@content, > "(\d{8}-\d*)-(\d*)") > > return ($debate-id) > > > > => > > > > <analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions"> > > <non-match>https://zoek.officielebekendmakingen.nl/h-tk-</non-match> > > <match> > > <group nr="1">20202021-102</group>-<group nr="2">1</group> > > </match> > > <non-match>/metadata.xml</non-match> > > </analyze-string-result> > > ... > > > > I am trying to extract the values from group 1 and 2 but this query > > returns 0 results: > > > > let $debates := collection("Parliament") > > for $debate-item in $debates > > let $item-file := $debate-item/officiele-publicatie//meta/@content > > let $debate-id := fn:analyze-string( > > $debate-item/officiele-publicatie//meta/@content, > "(\d{8}-\d*)-(\d*)") > > > > let $debate-nr := $debate-id//match/group[@nr="1"]/text() > > let $item-nr := $debate-id//match/group[@nr="2"]/text() > > > > return ($debate-nr, $item-nr) > > > > My guess is that analyze-string inserts new elements in the query and > > that that is the reason why this does not work. > > > > How can I extract debate-nr and item-nr from $debate-id? > > > > Ben Engbers > >