deucalion0
deucalion0

Reputation: 2440

How to correctly use XSD Duration?

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.

Upvotes: 1

Views: 3502

Answers (2)

Michael Kay
Michael Kay

Reputation: 163322

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.

Upvotes: 1

Michael Kay
Michael Kay

Reputation: 163322

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.

Upvotes: 1

Related Questions