전체 XML에 대해 빈 태그를 제거하는 XSL이 있지만 속성이 "DELETE"일 때 노드 섹션 하나에 대해 빈 태그를 제거하려고합니다. 모든 도움을 주시면 감사하겠습니다. 아래 예제 XML 및 XSL을 참조하십시오.특정 속성을 기반으로 XSL로 빈 노드 제거
XML 예제 : 아래
<?xml version="1.0" encoding="UTF-8"?>
<UGNX xmlns="http://www.ems-ag.de/xmlschemas/test/UGNX.XSD">
<Items Action="UPDATE">
<PartyCode>TSTeb</PartyCode>
<CatalogCode>TestCatalog</CatalogCode>
<Item Action="ADDORUPDATE">
<ItemCode>TST12345</ItemCode>
<ItemType>REGULAR</ItemType>
<ItemState>V</ItemState>
<AttributeAttachments Action="UPDATE">
<AttributeAttachment Action="DELETE">
<AttributeUID>
<PartyCode>TSTeb</PartyCode>
<AttributeClassificationCode>TestSchema
</AttributeClassificationCode>
<AttributeCode>TestAttribute</AttributeCode>
</AttributeUID>
<AttributeValues Action="REPLACE">
<Value Action="ADDORUPDATE">
<Order>0</Order>
<Enumeration/>
</Value>
</AttributeValues>
</AttributeAttachment>
<AttributeAttachment Action="ADDORUPDATE">
<AttributeUID>
<PartyCode>TSTeb</PartyCode>
<AttributeClassificationCode>TestSchema
</AttributeClassificationCode>
<AttributeCode>TestAttribute2</AttributeCode>
</AttributeUID>
<AttributeValues Action="REPLACE">
<Value Action="ADDORUPDATE">
<Order>0</Order>
<Translatable/>
</Value>
</AttributeValues>
</AttributeAttachment>
</AttributeAttachments>
</Item>
</Items>
</UGNX>
예상 결과. AttributeAttachment "Action"속성이 "DELETE"이면 빈 노드가 제거됩니다.
<?xml version="1.0" encoding="UTF-8"?>
<UGNX xmlns="http://www.ems-ag.de/xmlschemas/test/UGNX.XSD">
<Items Action="UPDATE">
<PartyCode>TSTeb</PartyCode>
<CatalogCode>TestCatalog</CatalogCode>
<Item Action="ADDORUPDATE">
<ItemCode>TST12345</ItemCode>
<ItemType>REGULAR</ItemType>
<ItemState>V</ItemState>
<AttributeAttachments Action="UPDATE">
<AttributeAttachment Action="DELETE">
<AttributeUID>
<PartyCode>TSTeb</PartyCode>
<AttributeClassificationCode>TestSchema
</AttributeClassificationCode>
<AttributeCode>TestAttribute</AttributeCode>
</AttributeUID>
<AttributeValues Action="REPLACE">
<Value Action="ADDORUPDATE">
<Order>0</Order>
</Value>
</AttributeValues>
</AttributeAttachment>
<AttributeAttachment Action="ADDORUPDATE">
<AttributeUID>
<PartyCode>TSTeb</PartyCode>
<AttributeClassificationCode>TestSchema
</AttributeClassificationCode>
<AttributeCode>TestAttribute2</AttributeCode>
</AttributeUID>
<AttributeValues Action="REPLACE">
<Value Action="ADDORUPDATE">
<Order>0</Order>
<Translatable/>
</Value>
</AttributeValues>
</AttributeAttachment>
</AttributeAttachments>
</Item>
</Items>
</UGNX>
현재 XSL :
<?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>
XML이 올바른 형식이 아닙니다. 고쳐주세요. 또한 첫 번째 XML과 두 번째 XML 간에는 차이점이없는 것 같습니다. – zx485
''과 같은 네스트 태그가 있다고 가정 해 보겠습니다. ''이 제거되면''이 비어있게되므로 ''도 제거 하시겠습니까? –
@ zx485 두 번째 XML에서는 일 때 Enumeration>이 제거되었습니다. –
Toya