我有以下輸入xml。
<response>
<customers>
<customer>
<id>001</id>
<addresses>
<address>
<id>a01</id>
<street/>
</address>
<address>
<id>a02</id>
<street/>
</address>
</addresses>
</customer>
<customer>
<id>002</id>
<addresses/>
</customer>
</customers>
如果子元素地址不存在或者它是空的(像這樣),我需要洗掉父元素客戶。
<response>
<customers>
<customer>
<id>001</id>
<addresses>
<address>
<id>a01</id>
<street/>
</address>
<address>
<id>a02</id>
<street/>
</address>
</addresses>
</customer>
</customers>
這是我使用的 xslt v 1.0,但它不起作用
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="customer[not(descendant::address[not(*)][normalize-space()])]"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
你能幫助我嗎?
uj5u.com熱心網友回復:
如果要排除customer
沒有address
后代的元素:
<xsl:template match="customer[not(descendant::address)]"/>
如果要排除customer
沒有具有address
某些text()
值后代的后代的元素:
<xsl:template match="customer[not(descendant::address[normalize-space()])]"/>
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/508599.html
上一篇:SQLServerXML查詢