xml에서 '빈'요소 (자식 없음, 속성 없음 또는 빈 속성)를 재귀 적으로 제거하려고합니다. 이것은 내가 가진 XSLT입니다
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="*[not(*) and
string-length(.)=0 and
(not(@*) or @*[string-length(.)=0])]">
<xsl:apply-templates/>
</xsl:template>
이것이 입력 XML입니다. 이 XML이 빈 문자열로 변환 될 것으로 예상합니다.
<world>
<country>
<state>
<city>
<suburb1></suburb1>
<suburb2></suburb2>
</city>
</state>
</country>
</world>
하지만 대신 나는
<world>
<country>
<state/>
</country>
</world>
누구든지 도울 수 있습니까? 포럼에서 많은 스레드를 조사했지만 여전히 운이 없습니다.
조건 not(*)
은 자식에 포함 된 내용에 관계없이 자식이있는 모든 요소에 대해 거짓입니다.
"과일"이없는 가지의 나무를 "가지 치기"하려면 다음을 시도하십시오.
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[descendant::text() or descendant-or-self::*/@*[string()]]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[string()]">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다