0

Is it possible to save each item in the elements in a xpath variable to use this value in same expression? The XPath expression have to be in one line. My goal is to transform the duration in milliseconds, in one expression.

XML

<pt:transcript
            xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1"
            version="0.1">
            <pt:segment contributor="timpritlove" start="00:00:43.101" end="00:00:49.300">Hallo und herzlich willkommen zu Forschergeist, dem Podcast des Stifterverbands für die deutsche Wissenschaft.</pt:segment>
            <pt:segment contributor="timpritlove" start="00:00:49.301" end="00:00:57.600">Mein Name ist Tim Pritlove und ich begrüße alle zu Ausgabe Nummer 72 hier in unserer Gesprächsreihe rund um Wissenschaft,</pt:segment>
            <pt:segment contributor="timpritlove" start="00:00:57.601" end="00:01:04.300">wissenschaftliche Fragen, manchmal geht es um Wissenschaft, manchmal geht es auch um die Metafragen der Wissenschaft.</pt:segment>
</pt:transcript>

XPath

fn:analyze-string(/pt:transcript/pt:segment[1]/@start, "[0-9][0-9]")

Result

Element='<analyze-string-result xmlns="http://www.w3.org/2005/xpath-functions">
   <match>00</match>
   <non-match>:</non-match>
   <match>00</match>
   <non-match>:</non-match>
   <match>43</match>
   <non-match>.</non-match>
   <match>10</match>
   <non-match>1</non-match>
</analyze-string-result>'
  • 2
    I'm not exactly clear what you are trying to achieve. Can you update the question with an example of the desired output, or clarify: are you trying to calculate the difference between `@start` and `@end` in milliseconds? Also, are you able to use XPath 2.0 or 3.0? – Mads Hansen Dec 12 '19 at 17:36

1 Answers1

0

From XPath 3.0 you can do

let $x := analyze-string(....)
return (some expression that references $x)
Michael Kay
  • 156,231
  • 11
  • 92
  • 164