How to correctly use XSD Duration?

青春壹個敷衍的年華 提交于 2019-12-23 02:57:19

问题


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>

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?

Should it maybe be used like this?:

<duration duration="PT5H30M"></duration>

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>

Any advice wold be appreciated, the XSD documentation is not helping me at all.


回答1:


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>

But the XSLT processor won't do this unless it's what your stylesheet requests.




回答2:


Without seeing your schema, I have no idea whether either (or both, or neither) of

<duration>PT5H30M</duration>

and

<duration duration="PT5H30M"></duration>

are valid instances, but the former seems more likely.

However, I provided my answer based on the second form, which is what I think the question looked like at the time I answered it - it has been edited subsequently.



来源:https://stackoverflow.com/questions/14925805/how-to-correctly-use-xsd-duration

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!