XML XSLT %0A%09%09 ?使固定?

标签 xml eclipse xslt

我的哈希 (#)“%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/

相关文章:

python - 如何在 Odoo 8 中使用 fields_view_get?

c - Eclipse:用 C 创建 Hello World 应用程序

eclipse - Perl 语法未突出显示

xslt - 根据其他元素的值删除元素 -- XSLT

xml - 如何使用 XQuery 提取特定的 XML 记录并以逗号分隔格式输出?

xml - 使用 JAXB 使用 XmlElement 和 XmlAttributes 解析和 XML

python - 如何删除 etree 元素的属性?

java - 如果我尝试读取的文件与我正在使用的 java 文件位于同一包中,为什么我仍然得到 "FileNotFoundException"?

xslt - 这是做什么的? <xsl :apply-templates select ="."/> and <xsl:apply-templates select ="*|@*"/>

java.lang.RuntimeException : Unable to start activity