Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xml 如何在xpath 3.1中使用分析字符串_Xml_Xslt_Xpath_Xsd - Fatal编程技术网

Xml 如何在xpath 3.1中使用分析字符串

Xml 如何在xpath 3.1中使用分析字符串,xml,xslt,xpath,xsd,Xml,Xslt,Xpath,Xsd,假设我想把像“03:02:22:11”这样的东西转换成毫秒。如何使用Xpath 3.1实现这一点 我试过:分析字符串(/pc:podcast/pc:eposion/pc:chapter,[([0-9]?[0-9]:)([0-5]?[0-9]:)?([0-5]?[0-9])([0-9][0-9]?[0-9]?)没有任何结果 下面是我的xml文件 <?xml version="1.0" encoding="UTF-8"?> <pc:podcast xmlns:pc="h

假设我想把像“03:02:22:11”这样的东西转换成毫秒。如何使用Xpath 3.1实现这一点

我试过:分析字符串(/pc:podcast/pc:eposion/pc:chapter,[([0-9]?[0-9]:)([0-5]?[0-9]:)?([0-5]?[0-9])([0-9][0-9]?[0-9]?)没有任何结果

下面是我的xml文件

 <?xml version="1.0" encoding="UTF-8"?>

<pc:podcast
    xmlns:pc="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast/0.3"
    xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="
        https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast/0.3
        podcast.xsd
        https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1
        podcast-transcript.xsd"
    url="https://forschergeist.de/"
    version="0.3">

    <pc:title>Forschergeist</pc:title>

    <pc:persons>
        <pc:person pid="timpritlove" gender="male">Tim Pritlove</pc:person>
        <pc:person pid="ritaadrian" gender="female">Rita Adrian</pc:person>
        <pc:person pid="peterpurgathofer" gender="male">Peter Purgathofer</pc:person>
        <pc:person pid="justushaucap" gender="male">Justus Haucap</pc:person>
        <pc:person pid="oliverparodi" gender="male">Oliver Parodi</pc:person>
        <pc:person pid="alinakokoschka" gender="female">Alina Kokoschka</pc:person>
    </pc:persons>

    <pc:episode episode="73" title="Klimawandel in Seen" date="2019-11-19T19:35:00" url="https://forschergeist.de/podcast/fg073-klimawandel-in-seen/" duration="01:23:14">
        <pc:contributor pid="timpritlove" role="host"/>
        <pc:contributor pid="ritaadrian" role="guest" />

        <pc:chapter number="1" duration="00:41" title="Intro" />
        <pc:chapter number="2" duration="01:14" title="Begrüßung" />
        <pc:chapter number="3" duration="04:41" title="Leibniz-Institut für Gewässerökologie und Binnenfischerei " />
        <pc:chapter number="4" duration="02:35" title="Persönlicher Werdegang" />
        <pc:chapter number="5" duration="04:44" title="Wissenschaftskultur in den USA" />
        <pc:chapter number="6" duration="06:34" title="Das Ökosystem der Binnenseen" />
        <pc:chapter number="7" duration="15:04" title="Langzeitbeobachtung der Seen" />
        <pc:chapter number="8" duration="12:46" title="Erkenntnisse aus den Messungen" />
        <pc:chapter number="9" duration="08:27" title="Veränderungen durch den Klimawandel" />
        <pc:chapter number="10" duration="03:10" title="Erforderliche Maßnahmen" />
        <pc:chapter number="11" duration="11:52" title="Wissenschaftliche Arbeit im IPCC" />
        <pc:chapter number="12" duration="10:02" title="Datenmanagement" />
        <pc:chapter number="13" duration="01:06" title="Ausklang" />

        <pt:transcript 
            xmlns:pt="https://purl.org/net/hbuschme/teaching/2019ws-infostruk/podcast-transcript/0.1"
            version="0.1">
        </pt:transcript>
    </pc:episode>

    <pc:episode episode="72" title="Verantwortung in der Informatik" date="2019-10-01T11:00:00" url="https://forschergeist.de/podcast/fg072-verantwortung-in-der-informatik/" duration="01:53:23">
        <pc:contributor pid="timpritlove" role="host"/>
        <pc:contributor pid="peterpurgathofer" role="guest" />

        <pc:chapter number="1" duration="00:42" title="Intro" />
        <pc:chapter number="2" duration="00:46" title="Begrüßung" />
        <pc:chapter number="3" duration="08:26" title="Peter Purgathofer" />
        <pc:chapter number="4" duration="09:26" title="Ethik und Moral in der Informatik" />
        <pc:chapter number="5" duration="06:41" title="Entscheidung und Verantwortung" />
        <pc:chapter number="6" duration="11:22" title="Denkweisen in der Informatik" />
        <pc:chapter number="7" duration="00:55" title="Strukturierung des Kurses" />
        <pc:chapter number="8" duration="05:31" title="Pre-Scientific Thinking" />
        <pc:chapter number="9" duration="04:15" title="Scientific Thinking" />
        <pc:chapter number="10" duration="06:01" title="Mathematical Thinking" />
        <pc:chapter number="11" duration="07:35" title="Computational Thinking" />
        <pc:chapter number="12" duration="09:57" title="Design Thinking" />
        <pc:chapter number="13" duration="10:20" title="Critical Thinking und Diversity" />
        <pc:chapter number="14" duration="05:15" title="Responsible Thinking" />
        <pc:chapter number="15" duration="04:00" title="Creative Thinking" />
        <pc:chapter number="16" duration="02:18" title="Economical Thinking" />
        <pc:chapter number="17" duration="04:07" title="Criminal Thinking" />
        <pc:chapter number="18" duration="02:07" title="Denkweisen für die Wissenschaft" />
        <pc:chapter number="19" duration="11:45" title="Der Reifegrad der Informatik" />
        <pc:chapter number="20" duration="01:43" title="Ausklang" />
  </pc:episode> 
    </pc:podcast>
我也尝试过这一点,它似乎有效:
let$string:=tokenize(string(//pc:eposion[1]/@duration),':')返回xs:integer($string[1])*3600000+xs:integer($string[2])*60000+xs:decimal($string[3]| | |,$string[4])*1000
我将利用
xs time
xs duration数据类型及其支持的算术操作:

let $time := xs:time('01:53:23.123'), $midnight := xs:time('00:00:00'), $duration := $time - $midnight return ($duration, $duration div xs:dayTimeDuration('PT0.001S'))
假设我想将类似“03:02:22:11”的内容转换为毫秒,那么如何使用Xpath 3.1实现这一点

首先,你没有解释语义。大概这意味着3小时2分钟22.11秒

我愿意

let $t := tokenize($input, ':')
return xs:integer($t[1])*3600000 + 
       xs:integer($t[2])*60000 + 
       xs:decimal($t[3] || '.' || $t[4])*1000
我不明白您为什么要为此使用
fn:analyze string

另一种选择是

xs:dayTimeDuration(replace($input, '(..):(..):(..):(..)', 'PT$1H$2M$3.$4S'))
    div xs:dayTimeDuration('PT0.001S')
我想我明白了:

let $string :="01:53:23.123", $regexpress :="(([0-9]?[0-9]):?([0-5]?[0-9])):?([0-5]?[0-9])(\.[0-9][0-9]?[0-9]?)?" return xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="2"]/string())*3600000+xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="3"]/string())*60000 + xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="4"]/string())*1000 + xs:decimal(analyze-string($string, $regexpress)//fn:group[@nr="5"]/string())*1000

现在我只需要if-then-else表达式…

如果您不清楚这个问题,请告诉我您是否有权访问任何提供XPath 3.1 API的软件?Saxon 9(XPath 3.1的9.8及更高版本)有一个。这将回答关于如何在XSLT之外使用XPath 3.1的一般问题。至于将持续时间转换为毫秒的问题,为什么要用
分析字符串
?@Martin Honnen解决这个问题,因为我们(我是一名大学生)我们必须使用分析字符串函数。此外,我们还必须使用if-else语句来区分小时和分钟)。所有这些都可以通过XPathTester工具完成(linkhttps://www.freeformatter.com/xpath-tester.html)该工具似乎不支持XPath3.1,仅支持3.0。但是如果您有一个测试/评估纯XPath3的工具,那么就使用它,不要在问题中问“没有xslt”。如果这是你的家庭作业,那么我想你必须自己解决。我建议你开始阅读XPath教程,例如,请参阅。是的,这似乎是一个合理的答案。我的目标是结合使用fn:analyze字符串和if-then-else表达式(以及变量的let表达式)。还有一个问题:如何使用div、mod和string连接将毫秒转换回标准格式(HH:MM:SS:millizes)?那么如何使用if-else.then函数确定字符串中是否包含小时和分钟?很抱歉提出这个问题,但我们之前没有讨论过这个话题,讲师/讲师也没有解释过。我想要类似“如果(小时和分钟在字符串中)然后标记化/fn:分析字符串并返回字符串的整数值。请务必编辑问题以提供问题的更精确说明。但请不要通过评论答案来更改问题。如果您想更改问题,通常最好从一个新线程重新开始。
let $string :="01:53:23.123", $regexpress :="(([0-9]?[0-9]):?([0-5]?[0-9])):?([0-5]?[0-9])(\.[0-9][0-9]?[0-9]?)?" return xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="2"]/string())*3600000+xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="3"]/string())*60000 + xs:integer(analyze-string($string, $regexpress)//fn:group[@nr="4"]/string())*1000 + xs:decimal(analyze-string($string, $regexpress)//fn:group[@nr="5"]/string())*1000