2012-03-10 46 views
2

我有下面的XML从XML元素中的空格

<list> 
    <foo attr1="value" attr2="red"> </foo> 
    <foo attr1="xx" attr2="blue"> </foo> 
    <foo attr1="yy" attr2="green"> </foo> 
</list> 

,我想成为:

<list> 
    <foo attr1="value" attr2="red"/> 
    <foo attr1="xx" attr2="blue"/> 
    <foo attr1="yy" attr2="green"/> 
</list> 

是否有删除的空间了foo的节点的XSLT的选择吗?

回答

5
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
     version="1.0"> 
<xsl:strip-space elements="foo"/> 
<xsl:template match="/"> 
<xsl:copy-of select="."/> 
</xsl:template> 
</xsl:stylesheet> 
0
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    version="1.0"> 

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

    <!--If the foo/text() is only whitespace, don't include in output--> 
    <xsl:template match="foo/text()[not(normalize-space())]"/> 

</xsl:stylesheet>