XSLT输出格式:保留换行符,删除缩进 [英] XSLT output formatting: keep line breaks, remove indent
本文介绍了XSLT输出格式:保留换行符,删除缩进的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的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):
This is the XSL (thanks 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>
到目前为止,一切都很好.我想
So far so good. I'd like to
- 保留换行符和
- 删除缩进
当我将输出缩进设置为是"时,会同时出现换行符和缩进. 当我将输出缩进设置为否"时,我什么也没得到.
When I set output indent to "yes", I get both, line-breaks and indents. When I set output indent to "no", I get none.
谢谢!
推荐答案
如果您不剥离也不缩进,而是将空白文本节点转换为换行符,如
If you don't strip and don't indent, but transform white space text nodes to a line break, as in
<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>
那么结果就是您想要的.
then the result is hopefully what you want.
这篇关于XSLT输出格式:保留换行符,删除缩进的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文