Created
November 6, 2023 15:30
-
-
Save sardinecan/d835b632dd78bdddffbcda0ed4725e43 to your computer and use it in GitHub Desktop.
XPointer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
declare function local:getIndex(){ | |
let $doc := | |
<div xml:id="transcription"> | |
<h1 xml:id="c1">Sélectionnez une portion de texte pour obtenir sa position</h1> | |
<p xml:id="c2">Lorem ipsum dolor sit amet, consectetur adipisicing elit. Asperiores cumque dignissimos dolore et, facilis iure iusto laborum neque, officiis quas quis velit? Dolor iure libero non optio repudiandae. Error, nulla.</p> | |
<p xml:id="c3">Lorem ipsum dolor sit amet, <span>consectetur</span> adipisicing elit. <span>Asperiores</span> cumque dignissimos dolore et, facilis iure iusto laborum neque, officiis quas quis velit? Dolor iure libero non optio repudiandae. Error, nulla.</p> | |
</div> | |
(: $xpointer récupéré depuis le doc html avec le couple JS/XForms :) | |
let $xpointer := ("//p[@xml:id='c3']", "consectetur adipisicing") | |
let $xpath := local:getXpath($xpointer[1]) | |
let $conteneur := fn:normalize-space($doc//*[fn:local-name() = $xpath[1]][@xml:id=$xpath[2]]) | |
return ( | |
"index : " || fn:string-length(fn:substring-before($conteneur, $xpointer[2]))+1, | |
"length : " || fn:string-length($xpointer[2]) | |
) | |
}; | |
declare function local:getXpath($xpath){ | |
let $node := fn:substring-before($xpath, "[") => fn:substring-after("//") | |
let $id := fn:substring-before($xpath, "']") => fn:substring-after( "='") | |
return ($node, $id) | |
}; | |
local:getIndex() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment