如何正确使用 XSD Duration? [英] How to correctly use XSD Duration?
问题描述
我试图在我的 XML 中存储一个时间间隔,它由我的 XSD 定义为我的 XSD 文件中的持续时间.我不知道如何使用它,但我正在尝试以下内容:
I am trying to store a time interval in my XML, which is defined by my XSD as duration in my XSD file. I am not sure how to use it though, the following is what I am attempting:
<duration>PT5H30M</duration>
这等于 5 小时 30 分钟.我在想,当 XSLT 文件将 XML 转换为 HTML 时,它会将持续时间转换为时间格式?
This is equal to 5 hours and 30 minutes. I was thinking that when the XSLT file transformed the XML into HTML, then it would convert the duration to a time format?
应该这样使用吗?:
<duration duration="PT5H30M"></duration>
这是我在 XSLT 文件中获取持续时间的位置:
Here is where I get the duration in my XSLT file:
<tr>
<td><xsl:attribute name="class">lside</xsl:attribute>Duration</td>
<td colspan="2"><xsl:attribute name="class">rside</xsl:attribute><xsl:value-of select="/flights/flight/route[routename/. = $code]/duration"/></td>
</tr>
感谢任何建议,XSD 文档根本没有帮助我.
Any advice wold be appreciated, the XSD documentation is not helping me at all.
推荐答案
好吧,如果您使用 XSLT 2.0,您可以轻松地将持续时间转换为这样的时间:
Well, if you use XSLT 2.0, you can easily convert a duration to a time like this:
<xsl:template match="duration">
<xsl:value-of select="xs:dayTimeDuration(@duration) + xs:time('00:00:00')"/>
</xsl:template>
但是 XSLT 处理器不会这样做,除非它是您的样式表所要求的.
But the XSLT processor won't do this unless it's what your stylesheet requests.
这篇关于如何正确使用 XSD Duration?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!