How to remove all text from an XML document

后端 未结 1 1839
别那么骄傲
别那么骄傲 2021-01-24 23:03

How can one remove all text, but leave the structure intact?

for example:


  
    cat
             


        
相关标签:
1条回答
  • 2021-01-24 23:21
    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:output method="xml" indent="yes"/>
    
      <!-- copy all nodes -->
      <xsl:template match="node()">
        <xsl:copy>
          <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
      </xsl:template>
    
      <!-- clear attributes -->
      <xsl:template match="@*">
        <xsl:attribute name="{name()}" />
      </xsl:template>
    
      <!-- ignore text content of nodex -->
      <xsl:template match="text()" />
    
    </xsl:stylesheet>
    
    0 讨论(0)
提交回复
热议问题