刚开始使用 xslt
需要在元素为空时删除元素
我做错了什么?
请帮助
这是我尝试解决问题时生成的一些代码
我的 xslt:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" .....>
<xsl:output method="xml" encoding="UTF-8" indent="yes"
xalan:indent-amount="2" />
<xsl:strip-space elements="*" />
<!--
The rule represents a custom mapping: "IdSelectFromDate" to
"IdSelectFromDate".
-->
<xsl:template name="IdSelectFromDateToIdSelectFromDate">
<xsl:param name="IdSelectFromDate" />
<!-- ADD CUSTOM CODE HERE. -->
<xsl:choose>
<xsl:when test="$IdSelectFromDate = ''">
<xsl:copy>
<xsl:apply-templates select="IdSelectFromDate" />
</xsl:copy>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="IdSelectFromDate" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="IdSelectFromDate" />
</xsl:stylesheet>
输入:
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:getRealEstateObjects>
<RequestElement>
<IdNumnet>IdNumnet</IdNumnet>
<IdSelectFromDate xsi:nil="true"/>
</RequestElement>
</tns:getRealEstateObjects>
</body>
所需的输出:
<?xml version="1.0" encoding="UTF-8"?>
<body xmlns:httpsca="http://www.ibm.com/xmlns/prod/websphere/http/sca/6.1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="foo.xsd">
<tns:getRealEstateObjects>
<RequestElement>
<IdNumnet>IdNumnet</IdNumnet>
</RequestElement>
</tns:getRealEstateObjects>
</body>