I am new to all this and have tried various route but I am not able to extract the data I need. The XML file that I am working with is automatically generated by a piece of hardware and its size generally about 35Kb. In the XML file there is a reference to a XSD file, which I do not have.
The information that I need to extract are as follows:
-n:D -n:S -filter : -node CUS with n:did='1', -child node CU with n:u='1' -grandchild node D with n:c='c' -sort the grandchild by n:f -extract the grand-grandchild n:Q -add all n:Q value for similar n:f from different nodes
As you can see below this is a very complex structure. Each time that I test for a condition on a node, I loose the entire XML structure in my output.
Here is part of the XML file:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:E xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:B>
<n:IR xmlns:n="http://abc.xxx/bb.xsd" n:result="0">
<n:D>2016/02/11 09:11:15</n:D>
<n:S>1</n:S>
<C n:t="3">
<D n:c="C" n:f="1" n:r="0" n:did="1">
<n:Q>10</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="5" n:r="0" n:did="1">
<n:Q>12</n:Q>
<n:St>2</n:St>
</D>
<D n:c="U" n:f="20" n:r="0" n:did="1">
<n:Q>1</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="U" n:f="5" n:r="0" n:did="1">
<n:Q>5</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="1" n:r="0" n:did="2">
<n:Q>5</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="100" n:r="0" n:did="2">
<n:Q>5</n:Q>
<n:St>2</n:St>
</D>
</C>
<C n:t="4">
<D n:c="C" n:f="1" n:r="0" n:did="1">
<n:Q>1</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="5" n:r="0" n:did="1">
<n:Q>2</n:Q>
<n:St>2</n:St>
</D>
<D n:c="U" n:f="20" n:r="0" n:did="1">
<n:Q>1</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="U" n:f="5" n:r="0" n:did="1">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="1" n:r="0" n:did="2">
<n:Q>2</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="100" n:r="0" n:did="2">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
</C>
<CUS n:did="1">
<CU n:u="1a" n:st="22" n:nf="90" n:ne="10" n:max="110"/>
<CU n:u="1" n:st="0" n:nf="100" n:ne="9" n:mx="105">
<D n:c="C" n:f="1" n:r="0" n:did="1">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="U" n:f="5" n:r="0" n:did="1">
<n:Q>12</n:Q>
<n:St>2</n:St>
</D>
</CU>
<CU n:u="2" n:st="0" n:nf="100" n:ne="9" n:mx="105"/>
...
<CU n:u="10" n:st="0" n:nf="100" n:ne="9" n:mx="105"/>
</CUS>
<CUS n:did="1">
<CU n:u="1" n:st="0" n:nf="100" n:ne="9" n:mx="105">
<D n:c="C" n:f="1" n:r="0" n:did="2">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="5" n:r="0" n:did="2">
<n:Q>12</n:Q>
<n:St>2</n:St>
</D>
</CU>
<CU n:u="2" n:st="0" n:nf="100" n:ne="9" n:mx="105"/>
...
<CU n:u="10" n:st="0" n:nf="100" n:ne="9" n:mx="105">
<D n:c="C" n:f="1" n:r="0" n:did="2">
<n:Q>4</n:Q>
<n:St>2</n:St>
</D>
...
<D n:c="C" n:f="5" n:r="0" n:did="2">
<n:Q>10</n:Q>
<n:St>2</n:St>
</D>
</CU>
</CUS>
</n:IR>
</soapenv:B>
</soapenv:E>
Here is the start of the XSL file in which I am trying to isolate the section of the XML file that I need:
<?xml version = "1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version = "1.0"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope"
xmlns:n="http://abc.xxx/bb.xsd">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*">
<xsl:apply-templates select="*"/>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:for-each select="//CU">
<xsl:copy/>
</xsl:for-each>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="C"/>
</xsl:stylesheet>
The result I get is:
<?xml version="1.0"?>
<soapenv:E xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:B>
<n:IR xmlns:n="http://abc.xxx/bb.xsd">
<n:D>2016/02/11 09:11:15</n:D>
<n:S>1</n:S>
<CUS>
<CU>
<D>
<n:Q>0</n:Q>
<n:St>0</n:St>
</D>
</CU>
<CU>
<D>
<n:Q>0</n:Q>
<n:St>0</n:St>
</D>
</CU>
....
</CUS>
</n:IR>
</soapenv:B>
</soapenv:E>
With this results, I no longer have the ability to filter nodes to extract the nodes I need to add data from.
Any suggestions?
Sorry for the typo n:Date should have been n:D above. The expected result should be something similar to this:
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:E xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:B>
<n:IR xmlns:n="http://abc.xxx/bb.xsd" n:result="0">
<n:Date>2016/02/11 09:11:15</n:Date>
<n:S>1</n:S>
<CUS n:did="1">
<CU n:u="1" n:st="0" n:nf="100" n:ne="9" n:mx="105">
<D n:c="C" n:f="5" n:r="0" n:did="1">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="10" n:r="0" n:did="1">
<n:Q>2</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="20" n:r="0" n:did="1">
<n:Q>5</n:Q>
<n:St>2</n:St>
</D>
</CU>
<CU n:u="2" n:st="0" n:nf="100" n:ne="9" n:mx="105">
<D n:c="C" n:f="5" n:r="0" n:did="1">
<n:Q>1</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="20" n:r="0" n:did="1">
<n:Q>1</n:Q>
<n:St>2</n:St>
</D>
<D n:c="C" n:f="50" n:r="0" n:did="1">
<n:Q>3</n:Q>
<n:St>2</n:St>
</D>
</CU>
</CUS>
</n:IR>
</soapenv:B>
</soapenv:E>
But the end result is a text format like this
2016/02/11 09:11:15,1,4,2,6,3
Where 4 is the sum n:Q from CU n:u='1' and n:U='2' for n:c='C', n:f='5' and n:did='1' and so on for the other values.