我尝试完成以下结构:
<?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>
这就是我的意见:
<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>
到目前为止我的xslt:
<?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>
我知道logistic Flat的这一部分是错误的,我尝试使用上面的分组,但由于logisticFlatRate段中没有索引,所以它不起作用。
我在货币和物流方面苦苦挣扎。我的目标是拥有一个像上面的例子一样的扁平结构
此代码:
<xsl:for-each select="/Response/Responses/logisticsFlatRate">
<xsl:copy-of select="."/>
</xsl:for-each>
显然是错误的,因为前导“/”从文档的根目录中进行选择,并且这里没有任何内容表明您要复制 which
logisticsFlatRate
。就此而言,您还没有告诉我们足够多的问题,让我们无法回答这个问题。但鉴于您的示例数据,您也许可以使用
<xsl:apply-templates select="current-group()/following-sibling::logisticsFlatRate"/>
加上适当的模板规则,将
logisticsFlatRate
转换为您在输出中实际想要的两个元素。