我遇到了一些XSLT问题。使用XSLT进行迭代时从XML文档中删除某些节点
我原来的XML看起来是这样的:
<?xml version="1.0"?><rowset>
<row>
<trans_type>10</trans_type>
<creation_date>2011-06-07</creation_date>
<system_id>1039</system_id>
<transaction_set>
<transaction>
<trans_type>10</trans_type>
<client_id>977400</client_id>
<case_id>12881459</case_id>
<invoice_no>01/2011</invoice_no>
<payment_date>110606</payment_date>
<payment>710,08</payment>
<currency>EUR</currency>
<comment>
<record_type>612</record_type>
<comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2</comment_text>
</comment>
<comment>
<record_type>612</record_type>
<comment_text>011. Meillä saldo 0 €.</comment_text>
</comment>
</transaction>
</transaction_set>
<subtotal>
<trans_type>10</trans_type>
<count>25</count>
</subtotal>
</row>
</rowset>
我的XSLT是这样的:
<?xml version='1.0' ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<rowset>
<xsl:for-each select="rowset/row/transaction_set/transaction">
<row>
<xsl:copy-of select="../../trans_type"/>
<xsl:copy-of select="../../creation_date"/>
<xsl:copy-of select="../../subtotal"/>
<xsl:copy-of select="."/>
<xsl:copy-of select="./client_id"/>
<comment_text><xsl:for-each select="./comment"><xsl:value-of select="./comment_text"/></xsl:for-each></comment_text>
</row>
</xsl:for-each>
</rowset>
</xsl:template>
</xsl:stylesheet>
...和我的输出是这样的:
<?xml version='1.0' ?>
<rowset>
<row>
<trans_type>10</trans_type>
<creation_date>2011-06-07</creation_date>
<subtotal>
<trans_type>10</trans_type>
<count>25</count>
</subtotal>
<transaction>
<trans_type>10</trans_type>
<client_id>977400</client_id> <!--need this gone-->
<case_id>12881459</case_id>
<invoice_no>01/2011</invoice_no>
<payment_date>110606</payment_date>
<payment>710,08</payment>
<currency>EUR</currency> <!--need this gone-->
<comment> <!--need this gone-->
<record_type>612</record_type>
<comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2</comment_text>
</comment>
<comment> <!--need this gone-->
<record_type>612</record_type>
<comment_text>011. Meillä saldo 0 €.</comment_text>
</comment>
</transaction>
<client_id>977400</client_id>
<comment_text>Asiakas maksoi lisäksi kesäkuun vuokran ajalle 1.6. - 15.6.2011. Meillä saldo 0 €.</comment_text>
</row>
</rowset>
我需要从我的输出中删除以下标签\rowset\row\transaction\comment
,\rowset\row\transaction\client_id
和\rowset\row\transcation\currency
。尽管我已经设法将XML转换成几乎我所需的方式,但似乎无法删除我不想要的节点。
在原始XML中,可以有多个transaction
在transaction_set
中,每个transaction
可以包含多个comment
。我试图连接所有我设法做的comment\comment_text
记录,但我需要在输出XML中从\rowset\row\transaction
中删除这些comment
标记。
也许我正在以错误的方式解决这个问题,但我无法理解它。
你尝试过什么?请记住,XSLT不是关于添加,删除或修改节点,而是关于创建一个全新的文档。你所要做的就是不把这些节点放在输出文档中。 – 2011-06-08 08:09:13