1
我正在開發一個XSLT,用於爲我的一些空的節點添加值。如果節點在一個或兩個父母的範圍內,它可以工作。XSLT不會替換樹中的空節點
<?xml version="1.0" encoding="UTF-8"?>
<VehicleDataCustom>
<VehicleDataCustomHeader>
<Commessa>SSP100</Commessa>
<RecordType />
<AttivitaAnnullamento />
</VehicleDataCustomHeader>
</VehicleDataCustom>
這裏是我的XSLT
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="AttivitaAnnullamento[not(node())]">
<xsl:copy>yes</xsl:copy>
</xsl:template>
</xsl:stylesheet>
它cleanely把一個是我得到的XML如下 -
<?xml version="1.0" encoding="UTF-8"?><VehicleDataCustom>
<VehicleDataCustomHeader>
<Commessa>SSP100</Commessa>
<RecordType/>
<AttivitaAnnullamento>yes</AttivitaAnnullamento>
</VehicleDataCustomHeader>
</VehicleDataCustom>
但如果我的XML的結構如下,它什麼也不做 -
<?xml version="1.0" encoding="UTF-8"?>
<ProcessVehicleDataCustom xmlns="http://schema.test.com/Testing/2" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://schema.test.com/2.2.0/Testing http://schema.test.com/2.2.0/Testing/BODs/Developer/ProcessVehicleDataCustom.xsd" releaseID="2">
<VehicleDataCustom>
<VehicleDataCustomHeader>
<Commessa>SSP100</Commessa>
<RecordType />
<AttivitaAnnullamento />
</VehicleDataCustomHeader>
</VehicleDataCustom>
</ProcessVehicleDataCustom>
不確定wha這個格式錯了。有沒有辦法處理這個標籤?我錯過了什麼嗎?
這是一個* namespace *問題,它已經被回答了很多次 - 例如,請參閱:http://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-根節點/ 34762628#34762628 –