我无法使用 XSLT 从我的 XML 中删除空节点。例如,XSLT 中的这个区域:
<RCPNT_NM>
<snm>
<xsl:value-of select="SNM"/>
</snm>
<gv_nm>
<xsl:value-of select="GVN_NM"/>
</gv_nm>
<init>
<xsl:value-of select="INIT"/>
</init>
</RCPNT_NM>
其中一些节点内的数据完全是空的,但我仍在取回它们。我尝试将match="node()|@*"
模板区域应用于 xslt,但这也不起作用。这是整个 XSLT 文件:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" version="2.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml" version="1.0"/>
<xsl:output indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<Return>
<xsl:apply-templates select="//IPERSON/item"/>
</Return>
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(@*) and not(*) and (not(text()) )]"/>
<xsl:template match="IPERSON/item">
<T5018Slip>
<RCPNT_NM>
<snm>
<xsl:value-of select="SNM"/>
</snm>
<gv_nm>
<xsl:value-of select="GVN_NM"/>
</gv_nm>
<init>
<xsl:value-of select="INIT"/>
</init>
</RCPNT_NM>
<sin>
<xsl:value-of select="SIN"/>
</sin>
<rcpnt_bn>
<xsl:value-of select="RCPNT_BN"/>
</rcpnt_bn>
<CORP_PTNRP_NM>
<l1_nm>
<xsl:value-of select="CORPL1_NM"/>
</l1_nm>
<l2_nm>
<xsl:value-of select="CORPL2_NM"/>
</l2_nm>
</CORP_PTNRP_NM>
<rcpnt_tcd>
<xsl:value-of select="RCPNT_TCD"/>
</rcpnt_tcd>
<RCPNT_ADDR>
<addr_l1_txt>
<xsl:value-of select="ADDR_L1_TXT"/>
</addr_l1_txt>
<addr_l2_txt>
<xsl:value-of select="ADDR_L2_TXT"/>
</addr_l2_txt>
<cty_nm>
<xsl:value-of select="CTY_NM"/>
</cty_nm>
<prov_cd>
<xsl:value-of select="PROV_CD"/>
</prov_cd>
<cntry_cd>
<xsl:value-of select="CNTRY_CD"/>
</cntry_cd>
<pstl_cd>
<xsl:value-of select="PSTL_CD"/>
</pstl_cd>
</RCPNT_ADDR>
<bn>
<xsl:value-of select="BN"/>
</bn>
<sbctrcr_amt>
<xsl:value-of select="SBCTRCR_AMT"/>
</sbctrcr_amt>
<rpt_tcd>
<xsl:value-of select="RPT_TCD"/>
</rpt_tcd>
</T5018Slip>
<xsl:for-each select="Return/T5018Summary/slp_cnt">
<xsl:value-of select="SLP_CNT='1'"/>
<xsl:if test="slp_cnt='1'">
<T5018Summary>
<bn>
<xsl:value-of select="BN1"/>
</bn>
<PAYR_NM>
<l1_nm>
<xsl:value-of select="L1_NM"/>
</l1_nm>
<l2_nm>
<xsl:value-of select="L2_NM"/>
</l2_nm>
<l3_nm>
<xsl:value-of select="L3_NM"/>
</l3_nm>
</PAYR_NM>
<PAYR_ADDR>
<addr_l1_txt>
<xsl:value-of select="PAYRADDR_L1_TXT"/>
</addr_l1_txt>
<addr_l2_txt>
<xsl:value-of select="PAYRADDR_L2_TXT"/>
</addr_l2_txt>
<cty_nm>
<xsl:value-of select="PAYRCTY_NM"/>
</cty_nm>
<prov_cd>
<xsl:value-of select="PAYRPROV_CD"/>
</prov_cd>
<cntry_cd>
<xsl:value-of select="PAYRCNTRY_CD"/>
</cntry_cd>
<pstl_cd>
<xsl:value-of select="PAYRPSTL_CD"/>
</pstl_cd>
</PAYR_ADDR>
<CNTC>
<cntc_nm>
<xsl:value-of select="CNTC_NM"/>
</cntc_nm>
<cntc_area_cd>
<xsl:value-of select="CNTC_AREA_CD"/>
</cntc_area_cd>
<cntc_phn_nbr>
<xsl:value-of select="CNTC_PHN_NBR"/>
</cntc_phn_nbr>
<cntc_extn_nbr>
<xsl:value-of select="CNTC_EXTN_NBR"/>
</cntc_extn_nbr>
</CNTC>
<PRD_END_DT>
<dy>
<xsl:value-of select="DY"/>
</dy>
<mo>
<xsl:value-of select="MO"/>
</mo>
<yr>
<xsl:value-of select="YR"/>
</yr>
</PRD_END_DT>
<slp_cnt>
<xsl:value-of select="SLP_CNT"/>
</slp_cnt>
<tot_sbctrcr_amt>
<xsl:value-of select="TOT_SBCTRCR_AMT"/>
</tot_sbctrcr_amt>
<rpt_tcd>
<xsl:value-of select="RPT_TCD"/>
</rpt_tcd>
</T5018Summary>
</xsl:if>
</xsl:for-each>
</xsl:template>