fn:node() returns the path to a node (including the text node): Is there a 
similar function to get character offsets within a text node? 

I am thinking of a case where, for example, one tokenizes a text within an 
element and would like to get the xpath + offsets for every token.


> On Jul 6, 2018, at 10:24 AM, Christian Grün <christian.gr...@gmail.com> wrote:
> 
> Hi Symantis,
> 
> The original line numbers are not stored in XML databases (they may
> change after updated, and would consume additional memory), so you
> won’t be able to retrieve them with XQuery.
> 
> As far as I know, this does not work in eXist-db either; the eXist
> link you referenced gives you the line of the util:line-number
> expression in your XQuery module. As Fabrice pointed out (thanks!),
> this could also be realized with $err:line-number.
> 
> With Saxon, it works indeed. However, you’ll need you use the -l
> command line option (otherwise, due to performance considerations,
> line numbers will be discarded as well).
> 
> On query/database level, there are two ways to get a direct reference:
> • With fn:path, you get an XPath expression that points to your node.
> • With db:node-pre [1], you get a direct reference to the node in a database.
> 
> Best,
> Christian
> 
> [1] http://docs.basex.org/wiki/Database_Module#db:node-id
> 
> 
> On Thu, Jul 5, 2018 at 5:49 PM Fabrice ETANCHAUD
> <fetanch...@pch.cerfrance.fr> wrote:
>> 
>> As BaseX does not work on the XML textual representation, it might not be 
>> possible.
>> 
>> 
>> 
>> 
>> 
>> De : BaseX-Talk [mailto:basex-talk-boun...@mailman.uni-konstanz.de] De la 
>> part de ????? ??????
>> Envoyé : jeudi 5 juillet 2018 17:10
>> À : basex-talk@mailman.uni-konstanz.de
>> Objet : [basex-talk] Add line-number function
>> 
>> 
>> 
>> 
>> 
>> 
>> 
>> Hello, could the $err:line-number [1] variable help you ?
>> 
>> [1] http://docs.basex.org/wiki/XQuery_3.0#Try.2FCatch
>> 
>> Best regards,
>> 
>> Fabrice ETANCHAUD
>> cerfrancepch
>> 
>> No, $err:line-number show line number of xquery file.
>> I want this:
>> 
>> Example.xml ->
>> 1: <root>
>> 2:   <child>
>> 3:      <grandchild>text1</grandchild>
>> 4:      <grandchild>text2</grandchild>
>> 5:      <grandchild>text3</grandchild>
>> 6:      <grandchild>text4</grandchild>
>> 7:    </child>
>> 8: </root>
>> 
>> Xquery ->
>> let $f := doc("example.xml")
>> let $e := $f/root/child[1]/grandchild[3]
>> 
>> let $line := line-number($e)
>> 
>> And I want get $line = 5 !
> 

Reply via email to