【发布时间】:2020-01-02 15:43:49
【问题描述】:
我需要转换我的 xml。
这是给我的xml
<InvoiceDocument>
<Invoice>
<d>100</d>
<a>120</a>
<Products>
<Product>
<b>11<b>
<c>12</c>
</Product>
<Product>
<b>13</b>
<c>14</c>
</Product>
</Products>
</Invoice>
</InvoiceDocument>
这是我需要的xml
<MessageParts>
<LedgerJournalTable class="entity>
<z>50</z>
<LedgerJournalTrans class="entity'>
<e>120</e>
</LedgerJournalTrans>
<LedgerJournalTrans class="entity'>
<g>11</g>
<h>12</h>
</LedgerJournalTrans>
<LedgerJournalTrans class="entity'>
<g>13</g>
<h>14</h>
</LedgerJournalTrans>
</LedgerJournalTable>
</MessageParts>
我尝试使用此代码转换我的 xml,但无法转换它
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="InvoiceDocument">
<MessageParts>
<LedgerJournalTable class="entity">
<z>50</z>
<LedgerJournalTrans class="entity'>
<xsl:apply-templates select="Invoice"/>
</LedgerJournalTrans>
<LedgerJournalTrans class="entity'>
<xsl:for-each select="Product">
<xsl:apply-templates select="Product"/>
</xsl:for-each>
</LedgerJournalTrans>
</LedgerJournalTable>
</MessageParts>
</xsl:template>
<xsl:template match="Invoice">
<e><xsl:value-of select="normalize-space(a/text()[1])"/></e>
</xsl:template>
<xsl:template match="Product">
<g><xsl:value-of select="normalize-space(b/text()[1])"/></g>
<h><xsl:value-of select="normalize-space(c/text()[1])"/></h>
</xsl:template>
</xsl:stylesheet>
我之前发错了问题,很抱歉
【问题讨论】: