Xml 完全删除注释(包括空格)的XSL
我有许多xml文件应遵循以下格式: 现在,我已经设置了一个xsl表,可以使用以下方法去除注释:Xml 完全删除注释(包括空格)的XSL,xml,xslt,whitespace,Xml,Xslt,Whitespace,我有许多xml文件应遵循以下格式: 现在,我已经设置了一个xsl表,可以使用以下方法去除注释: 以及其他一些身份模板应用程序 我会使用normalize-space(),但它会从答案文本中删除我确实需要的换行符。我正在寻找的是一种只删除“空白”或前后“额外”换行符的方法。有什么好办法吗 另请注意:最终输出是AdobeInDesign,它使用XSLT1.0 [编辑-XSL在下面] 00 此样式表: <xsl:stylesheet xmlns:xsl="http:/
以及其他一些身份模板应用程序
我会使用normalize-space(),但它会从答案文本中删除我确实需要的换行符。我正在寻找的是一种只删除“空白”或前后“额外”换行符的方法。有什么好办法吗
另请注意:最终输出是AdobeInDesign,它使用XSLT1.0
[编辑-XSL在下面]
00
此样式表:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()"/>
<xsl:template match="@choice">
<xsl:value-of select="concat(.,'	')"/>
</xsl:template>
<xsl:template match="question|answer">
<xsl:call-template name="identity"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
;
输出:
<root><question>What is the answer?</question>
<answer>A Some</answer>
<answer>B Answer</answer>
<answer>C Text</answer>
</root>
答案是什么?
一些
B答案
C文本
如果您能准确地展示到目前为止所做的工作(XSLT),并举例说明输出如何无法满足您的期望/要求,这将有所帮助。我已经添加了XSL并清理了输出。基本上,当注释被剥离时,它们会留下它们在xml文件中占用的原始空间,因为这个空间被认为是应答节点的一部分,所以剥离空间无法提取它。我也需要任何有意的返回,所以规范化空间也是不可能的。这会起作用,但我的输出是到Adobe InDesign,它需要一个节点树(我需要子节点,如、等,用于格式化)。@Pat:这不是你的问题。请发布您想要的输出。它位于问题的底部:“另请注意:最终输出是Adobe Indesign,它使用XSLT 1.0。”,但我没有提到它需要是一个节点树。经过反复试验,你的解决方案使我走上了正确的道路。非常感谢。
What is the answer?
A\t
Some
B\t
Answer
C\t
Text
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:strip-space elements="*" />
<xsl:template match = "@*|node()|processing-instruction()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()|processing-instruction()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()"/>
<xsl:template match="//answer"><xsl:value-of select="@choice"/>
<xsl:text>	</xsl:text><xsl:call-template name="identity"/>
</xsl:template>
<xsl:template match="//question">
<xsl:text>00	</xsl:text><xsl:call-template name="identity"/>
</xsl:template>
</xsl:stylesheet>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output omit-xml-declaration="yes"/>
<xsl:strip-space elements="*" />
<xsl:template match="@*|node()" name="identity">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="comment()"/>
<xsl:template match="@choice">
<xsl:value-of select="concat(.,'	')"/>
</xsl:template>
<xsl:template match="question|answer">
<xsl:call-template name="identity"/>
<xsl:text>
</xsl:text>
</xsl:template>
</xsl:stylesheet>
<root><question>What is the answer?</question>
<answer>A Some</answer>
<answer>B Answer</answer>
<answer>C Text</answer>
</root>