I have a XML doc that is transformed to HTML but I want the result HTML to be as small as possible. So I must remove all white spaces and line endings. How can I do that?
我有一个转换为HTML的XML文档,但我希望结果HTML尽可能小。所以我必须删除所有的空格和行尾。我怎么做呢?
4 个解决方案
#1
3
Using
使用
<xsl:strip-space elements="*"/>
is a good idea.
是一个好主意。
So is specifying the details of the output:
因此,指定输出的细节如下:
<xsl:output
indent="no"
method="html"/>
If the above still are not good enough, you can try altering the processing of text()
nodes (thinking along the lines of DocBook's schema, where any text you explicitly wanted would be in <para/>
tags, or similar):
如果上面的内容还不够好,您可以尝试修改text()节点的处理(按照DocBook的模式进行思考,在这里,您明确需要的任何文本将位于
<xsl:template match="chapter/text()"/>
You can use just match="text()"
but that might be too aggressive as it is very vague--it will not necessarily kill the text you want (again, in your <para/>
tags, or similar) as those text nodes will probably be processed implicitly by XSLT's built in templates.
您可以只使用match=“text()”,但这可能太过具有攻击性,因为它非常模糊——它并不一定会杀死您想要的文本(同样,在您的
#3
2
xsl:strip-space
will let you strip out whitespace from the result tree. Also make sure you don't generate extra whitespace in the stylesheet. That is, make sure instead of something like
条带空间将允许您从结果树中删除空格。还要确保在样式表中不生成额外的空格。也就是说,确保不是像这样
<xsl:value-of select="@key"/>
:
<xsl:value-of select="@value"/>
use xsl:text
使用xsl:文本
<xsl:value-of select="@key"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="@value"/>
#4
1
You should go with
你应该去跟
<xsl:strip-space elements="*"/>
#1
3
Using
使用
<xsl:strip-space elements="*"/>
is a good idea.
是一个好主意。
So is specifying the details of the output:
因此,指定输出的细节如下:
<xsl:output
indent="no"
method="html"/>
If the above still are not good enough, you can try altering the processing of text()
nodes (thinking along the lines of DocBook's schema, where any text you explicitly wanted would be in <para/>
tags, or similar):
如果上面的内容还不够好,您可以尝试修改text()节点的处理(按照DocBook的模式进行思考,在这里,您明确需要的任何文本将位于
<xsl:template match="chapter/text()"/>
You can use just match="text()"
but that might be too aggressive as it is very vague--it will not necessarily kill the text you want (again, in your <para/>
tags, or similar) as those text nodes will probably be processed implicitly by XSLT's built in templates.
您可以只使用match=“text()”,但这可能太过具有攻击性,因为它非常模糊——它并不一定会杀死您想要的文本(同样,在您的
#2
#3
2
xsl:strip-space
will let you strip out whitespace from the result tree. Also make sure you don't generate extra whitespace in the stylesheet. That is, make sure instead of something like
条带空间将允许您从结果树中删除空格。还要确保在样式表中不生成额外的空格。也就是说,确保不是像这样
<xsl:value-of select="@key"/>
:
<xsl:value-of select="@value"/>
use xsl:text
使用xsl:文本
<xsl:value-of select="@key"/>
<xsl:text>: </xsl:text>
<xsl:value-of select="@value"/>
#4
1
You should go with
你应该去跟
<xsl:strip-space elements="*"/>