这是我的 XML:
<doc>
<article>
<texte>
<notes>-</notes>
<content>
<title>T 1</title>
<argument>Arg 1</argument>
<p>Paragraph 1.1</p>
<p>Paragraph 1.2</p>
<p>Paragraph <i>1.3</i></p>
<short-author>FB</short-author>
</content>
<notes>-</notes>
<content>
<title>T2</title>
<p>Paragraph 2.1</p>
<short-author>JD</short-author>
</content>
<notes>-</notes>
<content>
<title>T3</title>
<argument>Arg 3</argument>
<p>Paragraph 3.1</p>
<short-author>NC</short-author>
</content>
</texte>
</article>
</doc>
这是 XSL(感谢 Dimitre):
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="//comment()"/>
<xsl:template match="@class" />
<xsl:template match="node()[not(self::doc|self::texte|self::author|self::style|self::span)]|@*" >
<xsl:copy>
<xsl:apply-templates select="node()[not(self::author)]|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
到目前为止,一切都很好。我想
当我将输出缩进设置为“是”时,我会得到换行符和缩进。
当我将输出缩进设置为“否”时,我什么也没有得到。
谢谢你!
如果您不剥离也不缩进,而是将空白文本节点转换为换行符,如下所示
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="comment()"/>
<xsl:template match="@class" />
<xsl:template match="node()[not(self::doc|self::texte|self::author|self::style|self::span)]|@*" >
<xsl:copy>
<xsl:apply-templates select="node()[not(self::author)]|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="text()[not(normalize-space())]">
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
那么结果就是你想要的。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)