在XSLT中,使用它会在渲染值之前生成一个换行符,在它之后生成另一个换行符。 这是一个例子:
<xsl:when test="name(.) = 'Item'">
"<xsl:value-of select="./Item/Data[last()]/text()"/>"
</xsl:when>
渲染结果为:
"
09/07/2012
"
如您所见,它在结果值之前和之后放置两个换行符,而期望的结果是:
"09/07/2012"
原始输入是:
这是原始输入,对不起。
<Item>
<Item>
<Data>105</Data>
<Data>09/07/2012</Data>
</Item>
</Item>
我在Oracle Server Bus中执行此XSLT
任何帮助将不胜感激。
答案 0 :(得分:3)
的额外空间也可以来自所选文本。使用normalize-space()
删除此内容。
<xsl:value-of select="normalize-space(./Item/Data[last()]/text())"/>
编辑 Overnuts在引号周围使用<xsl:text>
是正确的,否则Xslt处理器会在开头/ 之后保留换行符 收尾报价。但是,我仍然无法理解为什么换行符可以介于引号和xsl:value-of
之间?
我尝试了以下
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/xml" xml:space="default">
<xsl:apply-templates select="*" />
</xsl:template>
<xsl:template match="*" xml:space="default">
<xsl:choose>
<xsl:when test="name(.) = 'Item'">
<xsl:text>"</xsl:text>
<xsl:value-of select="normalize-space(./Item/Data[last()]/text())"/>
<xsl:text>"</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
使用此XML运行时:
<xml>
<Item>
<Item>
<Data>105</Data>
<Data>09/07/2012</Data>
</Item>
</Item>
</xml>
制作"09/07/2012"
答案 1 :(得分:3)
我想你可以试试:
一条线上的所有东西(快速而肮脏):
<xsl:when test="name(.) = 'Item'">"<xsl:value-of select="./Item/Data[last()]/text()"/>"</xsl:when>
或使用此类标签(最佳做法):
<xsl:when test="name(.) = 'Item'">
<xsl:text>"</xsl:text>
<xsl:value-of select="./Item/Data[last()]/text()"/>
<xsl:text>"</xsl:text>
</xsl:when>
答案 2 :(得分:0)
原始XML源可能包含这些换行符(缩进),尝试类似:
<xsl:value-of select="concat('~', normalize-space(./Item/Data[last()]/text()), '~')"/>
答案 3 :(得分:0)
也许是特定于实现的错误?
使用xsltproc所有上述工作都按预期工作,尽管裸线换行+空白+引号+日期+引号+换行+空格的预期结果也是要复制/ external / white-space。所有其他示例产生相同的13个字节,包括尾随换行符。
使用libxml 20706,libxslt 10124和libexslt 813 xsltproc是针对libxml 20701,libxslt 10124和libexslt 813编译的 libxslt 10124是针对libxml 20701编译的 libexslt 813是针对libxml 20701编译的