i try to accomplish the following structure:
<?xml version="1.0" encoding="UTF-8"?>
<Response>
<Responses>
<index>000010</index>
<brutto>246.09</brutto>
<bruttoSingle>246.09</bruttoSingle>
<netto>7327.14</netto>
<nettoSingle>244.24</nettoSingle>
<logisticsFlatRatValue>18.27</<logisticsFlatRatValue>
<logisticsFlatRatpercentage>0.25</logisticsFlatRatpercentage>
<Currency>USD</Currency>
</Responses>
<Responses/>
<Responses>
<index>000020</index>
<brutto>10.20</brutto>
<bruttoSingle>10.20</bruttoSingle>
<netto>2.88</netto>
<nettoSingle>2.88</nettoSingle
<logisticsFlatRatValue>18.27</<logisticsFlatRatValue>
<logisticsFlatRatpercentage>0.25</logisticsFlatRatpercentage>
<Currency>USD</Currency>
</Responses>
<Responses/>
</Response>
Thats my input:
<Response>
<Responses>
<brutto>
<indx>000010</indx>
<value>246.09</value>
<currency>USD</currency>
</brutto>
<bruttoSingle>
<indx>000010</indx>
<value>246.09</value>
<currency>USD</currency>
</bruttoSingle>
<logisticsFlatRate>
<value>18.27</value>
<percentage>0.25</percentage>
</logisticsFlatRate>
</Responses>
<Responses>
<netto>
<indx>000010</indx>
<value>7327.14</value>
<currency>USD</currency>
</netto>
<nettoSingle>
<indx>000010</indx>
<value>244.24</value>
<currency>USD</currency>
</nettoSingle>
</Responses>
<Responses/>
<Responses>
<brutto>
<indx>000020</indx>
<value>10.20</value>
<currency>USD</currency>
</brutto>
<bruttoSingle>
<indx>000020</indx>
<value>10.20</value>
<currency>USD</currency>
</bruttoSingle>
</Responses>
<Responses>
<netto>
<indx>000020</indx>
<value>2.88</value>
<currency>USD</currency>
</netto>
<nettoSingle>
<indx>000020</indx>
<value>2.88</value>
<currency>USD</currency>
</nettoSingle>
<logisticsFlatRate>
<value>15.27</value>
<percentage>0.45</percentage>
</logisticsFlatRate>
</Responses>
<Responses/>
</Response>
My xslt so far:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<xsl:for-each-group select="//Responses/*[index]" group-by="index">
<group>
<index><xsl:value-of select="current-grouping-key()"/></index>
<items>
<xsl:for-each select="current-group()">
<xsl:element name="{name()}">
<xsl:value-of select="value"/>
</xsl:element>
</xsl:for-each>
<xsl:for-each select="/Response/Responses/logisticsFlatRate">
<xsl:copy-of select="."/>
</xsl:for-each>
</items>
</group>
</xsl:for-each-group>
</xsl:template>
</xsl:stylesheet>
i know this part with the logistc flat is wrong and i tried using the grouping from above, but since there is no index in the logisticFlatRate segment it dindt work.
im struggling on the currency and the logisticflat. My goal is to have a flat structure like from my example above
This code:
<xsl:for-each select="/Response/Responses/logisticsFlatRate">
<xsl:copy-of select="."/>
</xsl:for-each>
is clearly wrong, because a leading "/" selects from the root of the document, and there's nothing here that says which logisticsFlatRate
you want to copy. And for that matter, you haven't told us enough about the problem for us to answer that question. But given your sample data, you might be able to use
<xsl:apply-templates select="current-group()/following-sibling::logisticsFlatRate"/>
plus an appropriate template rule to convert the logisticsFlatRate
into the two elements you actually want in your output.