我有一个XML文档转换为HTML,但我希望结果HTML尽可能小。 所以我必须删除所有的空格和行结尾。 我怎样才能做到这一点?
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?
最满意答案
运用
<xsl:strip-space elements="*"/>是个好主意。
那么是指定输出的细节:
<xsl:output indent="no" method="html"/>如果上述仍然不够好,您可以尝试更改text()节点的处理(按照DocBook架构的思路,您明确需要的任何文本将位于<para/>标记中或类似的地方):
<xsl:template match="chapter/text()"/>你可以只使用match="text()"但它可能过于激进,因为它非常模糊 - 它不一定会杀死你想要的文本(再次,在你的<para/>标记或类似的文本中)节点可能会被XSLT的内置模板隐式处理。
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):
<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.
XSLT:在转换为HTML时删除空格(XSLT: remove white spaces when transforming to HTML)我有一个XML文档转换为HTML,但我希望结果HTML尽可能小。 所以我必须删除所有的空格和行结尾。 我怎样才能做到这一点?
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?
最满意答案
运用
<xsl:strip-space elements="*"/>是个好主意。
那么是指定输出的细节:
<xsl:output indent="no" method="html"/>如果上述仍然不够好,您可以尝试更改text()节点的处理(按照DocBook架构的思路,您明确需要的任何文本将位于<para/>标记中或类似的地方):
<xsl:template match="chapter/text()"/>你可以只使用match="text()"但它可能过于激进,因为它非常模糊 - 它不一定会杀死你想要的文本(再次,在你的<para/>标记或类似的文本中)节点可能会被XSLT的内置模板隐式处理。
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):
<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.
发布评论