【问题标题】:does Saxon use whitespace in attribute during XSLT?Saxon 在 XSLT 期间是否在属性中使用空格?
【发布时间】:2012-09-06 20:30:48
【问题描述】:

我想知道 Saxon 在 XSLT 期间如何以及为什么在 XSL 元素之间使用空格。以下是可能受上述行为影响的示例:

Saxon 在 XSLT 期间如何以及为何在 XSL 元素之间使用空格?

<div style="display:none;">
    <xsl:choose>
      <xsl:when test="true">
        <xsl:attribute name="id">
           <xsl:choose>
              <xsl:when>
               etc ec
              </xsl:when>
              <xsl:otherwise></xsl:otherwise>
            </xsl:choose>
          </xsl:attribute>
         </xsl:when>
         <xsl:otherwise></xsl:otherwise>

</div>

为什么&lt;div&lt;xsl:choose&gt; 之间的空格可能会导致以下错误:

XSLT attribute node (id) cannot be created after the children of the containing element

【问题讨论】:

  • 您缺少第一个 &lt;xsl:choose&gt; 的结束标记

标签: xslt saxon


【解决方案1】:

只包含空格的文本节点(如您的示例中的那个)没有效果(它们在解析的早期阶段被删除)除非您碰巧在某些父元素上具有属性 xml:space="preserve"在样式表中。 (由于这样的原因,将 xml:space="preserve" 放入样式表中几乎总是坏消息,但人们时不时会这样做,这可能会导致这里出现问题。)

另一种可能性(我在 12 年内只见过一次......)是看起来像空格的东西不是。例如,它可能包含不间断空格或零宽度空格,它们看起来是白色的,但不是正式的空格。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-03-21
    • 2014-05-11
    • 2012-02-09
    • 2011-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-01-18
    • 2010-10-11
    相关资源
    最近更新 更多