2013-09-12 2 views
0

필자는 빈 태그 (필수 필드 제외)를 출력에서 ​​제외해야합니다. 필수 필드는 비어있는 경우에도 출력에 있어야합니다.XSLT : 출력에서 ​​몇 개의 빈 태그 만 제외하는 방법은 무엇입니까?

다음 xslt를 사용하여 빈 태그를 제외 할 수 있습니다. 그러나 필수 필드조차도 비어있는 경우 출력에서 ​​제거됩니다. 제발 조언.

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/> 
<xsl:strip-space elements="*"/> 

<xsl:template match="node()|@*"> 
<xsl:copy> 
    <xsl:apply-templates select="node()|@*"/> 
</xsl:copy> 
</xsl:template> 

<xsl:template match= "*[not(@*|*|comment()|processing-instruction()) and  
normalizespace()='']"/> 
</xsl:stylesheet> 

답변

1

변경

<xsl:template match= "*[not(@*|*|comment()|processing-instruction()) and  
normalizespace()='']"/> 

당신이 foo, bar, foobar 당신의 필수 요소의 이름으로 대체

<xsl:template match= "*[not(@*|*|comment()|processing-instruction()) and  
normalizespace()='' and not(self::foo | self::bar | self::foobar)]"/> 

합니다.

1

난 당신 만 제거 할 요소의 이름을 지정 끝낼 수 있다고 생각 :

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output omit-xml-declaration="yes" indent="yes" method="xml"/> 
    <xsl:strip-space elements="*"/> 

    <!-- Identity template --> 
    <xsl:template match="node()|@*"> 
     <xsl:copy> 
      <xsl:apply-templates select="node()|@*"/> 
     </xsl:copy> 
    </xsl:template> 

    <!-- Remove the following elements --> 
    <xsl:template match="element1 | element2 | element3"/> 
</xsl:stylesheet> 
관련 문제