Re: [basex-talk] How to extract value from fn:analyze-string
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) > > > > => > > > > http://www.w3.org/2005/xpath-functions;> > >https://zoek.officielebekendmakingen.nl/h-tk- > > > > 20202021-102-1 > > > >/metadata.xml > > > > ... > > > > 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 > >
Re: [basex-talk] How to extract value from fn:analyze-string
I'll experiment a little with the namespace but for the moment adding *: works! Thanks, Ben Op 10-02-2022 om 18:46 schreef Imsieke, Gerrit, le-tex: 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) => http://www.w3.org/2005/xpath-functions;> https://zoek.officielebekendmakingen.nl/h-tk- 20202021-102-1 /metadata.xml ... 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
Re: [basex-talk] How to extract value from fn:analyze-string
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) => http://www.w3.org/2005/xpath-functions;> https://zoek.officielebekendmakingen.nl/h-tk- 20202021-102-1 /metadata.xml ... 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
Re: [basex-talk] How to extract value from fn:analyze-string
Include the namespace, or put in a wildcard; eg let $debate-nr := $debate-id//*:match/*:group[@nr="1"]/text() let $item-nr := $debate-id//*:match/*:group[@nr="2"]/text() I'm mobile at the moment, but think that's right (: untested and off the cuff, in other words :). Best, Bridger On Thu, Feb 10, 2022, 12:30 PM 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) > > => > > http://www.w3.org/2005/xpath-functions;> >https://zoek.officielebekendmakingen.nl/h-tk- > > 20202021-102-1 > >/metadata.xml > > ... > > 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 >