null 노드를 삭제할 필요가 있지만 특정 속성 "DELETE"의 값으로 공백이있는 노드를 유지해야합니다. XSL에 익숙하지 않습니다 ... null 값을 제거하지만 공간 값을 유지하려면 어떻게해야합니까?XSL - 공백 태그 제거 및 공백 보유
"DELETE"동작이있는 노드에만 적합합니다. 예를 들어, 조치가 "DELETE"일 때 다른 노드 이름이 무엇이든 상관없이 (변경 될 것이므로) 널 값의 하위 노드는 삭제되어야합니다. 이것이 가능하지 않다면, 전체 XML 파일에서 null 값을 제거해야합니다.이 코드는 작동하고 아래에 나열되어 있습니다. 그러나 공백을 유지하지 않으며 "DELETE"속성 만위한 것이 아닙니다. 아래의 예.
<?xml version="1.0" encoding="utf-8"?>
<test xmlns:n0="http://mynamespace">
<Value Action="DELETE">
<Example1> </Example1>
<Test2 />
<Example3></Example3>
</Value>
<Value Action="UPDATE">
<space> </space>
<null />
<null2></null2>
</Value>
</test>
예상 결과 :
<?xml version="1.0" encoding="utf-8"?>
<test xmlns:n0="http://mynamespace">
<Value Action="DELETE">
<Example1> </Example1>
</Value>
<Value Action="UPDATE">
<space> </space>
<null />
<null2></null2>
</Value>
</test>
모든 널 (null)을 제거
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:strip-space elements="*"/>
<xsl:template match="*">
<xsl:if test=". != '' or ./@* != ''">
<xsl:element name="{local-name()}">
<xsl:apply-templates select="@* | node()" />
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
<xsl:template match="text() | comment() | processing-instruction()">
<xsl:copy />
</xsl:template>
</xsl:stylesheet>
. 감사. – Toya
질문이 수정되었습니다. – Toya