2013-04-15 56 views

回答

0

是的,你可以做這樣的事情:

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

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

    <xsl:template match="text()"> 
    <xsl:value-of select="normalize-space()" /> 
    </xsl:template> 
</xsl:stylesheet> 

當此輸入運行:

<root> 
    <mynode> 

    here is some text <!-- That is some text --> 

    and here is some other text 

    <!-- That was some other text --> 
    </mynode> 

    <!-- Here are some more comments --> 
</root> 

結果是:

<root><mynode>here is some text<!-- That is some text -->and here is some other text<!-- That was some other text --></mynode><!-- Here are some more comments --></root> 

展示你如何做到這種融入實際執行的XSLT的東西:

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

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

    <xsl:template match="text()"> 
    <xsl:value-of select="normalize-space()" /> 
    </xsl:template> 

    <xsl:template match="/"> 
    <myNewRoot> 
     <myNewNode> 
     <xsl:apply-templates select="root/mynode/node()" /> 
     </myNewNode> 
    </myNewRoot> 
    </xsl:template> 
</xsl:stylesheet> 

當這上面的投入運行,其結果是:

<myNewRoot> 
    <myNewNode>here is some text<!-- That is some text -->and here is some other text<!-- That was some other text --></myNewNode> 
</myNewRoot>