我的哈希 (#)“%0A%09%09#2”前面附加了奇怪的字符,我使用的是 Eclipse 和 java 处理器 Xalan 2.7.1
<xsl:for-each select="fps-photo-atlas/portion">
<a>
<xsl:attribute name="href" >
#<xsl:value-of select="normalize-space(food-number)" />
</xsl:attribute>
<xsl:value-of select="food-description" />
</a>
</xsl:for-each>
首选输出是...
<body><a href="#1">Rice </a></body>
实际输出是..
<body><a href="%0A%09%09#1">Rice </a></body>
修复了它的解决方案(感谢 Ign)
<xsl:attribute name="href" >#<xsl:value-of select="normalize-space(food-number)" /></xsl:attribute>
最佳答案
样式表中的文本节点的值为 whitespace stripped除非满足以下条件之一:
- 它直接位于“xsl:text”元素内
- 它包含非空白字符
- 它是通过使用“xml:space”属性保留的
不需要的空格与 # 字符位于同一文本节点中,因此被保留。
有多种方法可以排除不需要的空格。
使用 Attribute Value Template而不是“xsl:attribute”。
<a href="#{normalize-space(food-number)}">
<xsl:value-of select="food-description" />
</a>
将 # 字符移动到“xsl:text”元素中。
<a>
<xsl:attribute name="href" >
<xsl:text>#</xsl:text>
<xsl:value-of select="normalize-space(food-number)" />
</xsl:attribute>
<xsl:value-of select="food-description" />
</a>
将 # 字符移至“value-of”表达式中。
<a>
<xsl:attribute name="href" >
<xsl:value-of select="concat('#',normalize-space(food-number))" />
</xsl:attribute>
<xsl:value-of select="food-description" />
</a>
从样式表中删除空格。
<a>
<xsl:attribute name="href" >#<xsl:value-of select="normalize-space(food-number)></xsl:attribute>
<xsl:value-of select="food-description" />
</a>
关于XML XSLT %0A%09%09 ?使固定?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10405988/