Jump to content

extract hour from dateand put it in a new tag


Amyla

Recommended Posts

Hi all,

I need help with this xml file:

<?xml version="1.0" encoding="ISO-8859-1"?>
<output>
<orders>
<order>
<id>1</id>
<number>10002</number>
<type>Loading</type>
<date>2013-01-01T02:30:00</date>
</order>
<order>
<id>2</id>
<number>10003</number>
<type>Loading</type>
<date>2013-01-01T010:30:00</date>
</order>
<order>
<id>3</id>
<number>10004</number>
<type>Loaded</type>
<date>2013-01-01T12:30:00</date>
</order>
</orders>
<quantities>
<quantity>
<id_order>1</id_order>
<unit>KG</unit>
<value>1000</value>
</quantity>
<quantity>
<id_order>1</id_order>
<unit>PAL</unit>
<value>3</value>
</quantity>
<quantity>
<id_order>1</id_order>
<unit>M3</unit>
<value>1.5</value>
</quantity>
<quantity>
<id_order>2</id_order>
<unit>KG</unit>
<value>2000</value>
</quantity>
<quantity>
<id_order>2</id_order>
<unit>PAL</unit>
<value>4</value>
</quantity>
<quantity>
<id_order>3</id_order>
<unit>KG</unit>
<value>5000</value>
</quantity>
</quantities>
</output>
i need to add an extra tag <hour> after >date> nd in this new tg put te value of time (hh:mm) find in date.
I've managed to do this (but it only create the tag and don't put th hours in it)
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="date">
<xsl:copy-of select="."/>
<hour>
<xsl:value-of select="substring(output/orders/order/date,12,5)"/>
</hour>
</xsl:template>
</xsl:stylesheet>
please help me
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...