09:20:00<...">

Add / subtract time in XSLT

I am using xpath 2.0.

I want to add 30 minutes to the $orario variable.

  <tempi id="ID_1"> <orario_part>09:20:00</orario_part> ... </tempi> 

This is my code, but it does not work.

 <xsl:template match="tempi"> <xsl:variable name="orario" select="./orario_part"/> <xsl:variable name="totale" select="xs:time($orario)+xs:time('00:30:00')"/> <time> <xsl:value-of select="$totale"/> </time> </xsl:template> 

Below is the desired result:

 <time>09:50:00</time> 

How can i do this?

+4
source share
1 answer

Try the following:

 <?xml version="1.0" encoding="UTF-8"?> <tempi id="ID_1"> <orario_part>09:20:00</orario_part> </tempi> 

and

 <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" version="2.0" exclude-result-prefixes="#all"> <xsl:template match="tempi"> <xsl:variable name="orario" select="./orario_part" /> <xsl:variable name="totale" select="xs:time($orario)"/> <time> <xsl:value-of select="$totale + xs:dayTimeDuration('P0DT0H30M')"/> </time> </xsl:template> </xsl:stylesheet> 

gives

 <time>09:50:00</time> 
+4
source

All Articles