【发布时间】:2014-02-05 20:45:35
【问题描述】:
愚蠢的,简单的问题。当我输出文本时,它仍然会根据我的格式化/缩进 XSL 结构获取选项卡。如何指示转换器忽略样式表中的间距,同时仍保持其格式整齐?
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="Foo/Bar"></xsl:apply-templates>
</xsl:template>
<xsl:template match="Bar">
<xsl:for-each select="AAA"><xsl:for-each select="BBB"><xsl:value-of select="Label"/>|<xsl:value-of select="Value"/><xsl:text> </xsl:text></xsl:for-each></xsl:for-each>
</xsl:template>
</xsl:stylesheet>
逐行生成输出,没有制表符:
SomeLabel|SomeValue
SomeLabel|SomeValue
SomeLabel|SomeValue
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates select="Foo/Bar"></xsl:apply-templates>
</xsl:template>
<xsl:template match="Bar">
<xsl:for-each select="AAA">
<xsl:for-each select="BBB">
<xsl:value-of select="Label"/>|<xsl:value-of select="Value"/>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
使用标签生成输出:
SomeLabel|SomeValue
SomeLabel|SomeValue
SomeLabel|SomeValue
更新: 添加这个并不能解决它:
<xsl:output method="text" indent="no"/>
<xsl:strip-space elements="*"></xsl:strip-space>
这是人为的,但您可以想象 XML 看起来像这样:
<Foo>
<Bar>
<AAA>
<BBB>
<Label>SomeLabel1</Label>
<Value>SomeValue1</Value>
</BBB>
<BBB>
<Label>SomeLabel2</Label>
<Value>SomeValue2</Value>
</BBB>
<BBB>
<Label>SomeLabel3</Label>
<Value>SomeValue3</Value>
</BBB>
</AAA>
</Bar>
</Foo>
【问题讨论】:
-
您发布的 XSLT 代码不会产生您声称的结果:xsltransform.net/pPgCcop
-
@michael.hor257k 已更新。 xsltransform.net 上的缩进是正确的,但我在 Visual Studio 和 notepad++ 中运行了它,并且当 XSLT 缩进时,两者都将制表符插入到输出中。
标签: xslt formatting