I need to:
- Transform the
input.xml
(file below) to the format of output.xml
- Create another XLS that will display per each amount:
KG
, PAL
and M3
the
total values;
- Replace the tag
<quantity>
with the tag <amount>
in the same XSL from
point 2;
- create another XSL which is just adding an extra tag
<hour>
for each
<order>
and display inside this tag the hour of loading (hh:MM
)
But at first I need to convert this file (input.xml
):
<?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>
To this file (output.xml
):
<?xml version="1.0" encoding="ISO-8859-1"?>
<output>
<orders>
<order>
<id>1</id>
<number>10002</number>
<type>Loading</type>
<KG>1000</KG>
<PAL>3</PAL>
<M3>1.5</M3>
</order>
<order>
<id>2</id>
<number>10003</number>
<type>Loading</type>
<KG>2000</KG>
<PAL>4</PAL>
</order>
<order>
<id>3</id>
<number>10004</number>
<type>Loaded</type>
<KG>5000</KG>
</order>
</orders>
</output>
I tried this one but it is not complete, I don't know how to convert values (like: PAL
in input file) to atributes (like <PAL>...</PAL>
in output file). I have looked around and tried few things but it is not working. Can someone help me with this. Below is my XSLT. Thanks in advance.
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl: template match = "/">
<output>
<xsl: for-each select = "orders/order[id = 1]">
<order>
<xsl: value-of select = "id"/>
<xsl: value-of select = "number"/>
<xsl: value-of select = "type"/>
</order>
</xsl: for-each>
<xsl: for-each select = "quantities/quantity">
<order>
<xsl: value-of select = "id"/>
<xsl: value-of select = "number"/>
<xsl: value-of select = "type"/>
</order>
</xsl: for-each>
</output>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…