【问题标题】:XSLT attribute node (id) cannot be created after the children of the containing element不能在包含元素的子元素之后创建 XSLT 属性节点 (id)
【发布时间】:2012-08-30 15:12:53
【问题描述】:

通常我在 Weblogic12 服务器上执行 XSLT 进程。我一直遇到这个问题

net.sf.saxon.trans.DynamicError: An attribute node 
(id) cannot be created after the children of the containing element

在迁移之前,我们的团队完全没有问题...

知道为什么吗?我最近从 BEA Weblogic3 升级到 Oracle Enterprise Weblogic 12。还是我缺少库?

这困扰着我们整个团队!谢谢!

编辑 1:

<xsl:template name="makeErrorDiv"> 中的错误指向<xsl:attribute name="id">

<td>
            <xsl:copy-of select="@colspan | @align | @style | @valign | @class | @id | @name"/>
            <xsl:if test="@colspan = '1' and $columnWidth != '' and not(@suppressColWidth='true')"><xsl:attribute name="width"><xsl:value-of select="$columnWidth"/></xsl:attribute></xsl:if>
            <xsl:if test="@rowspan != '1'"><xsl:copy-of select="@rowspan"/></xsl:if>

            <xsl:if test="descendant::ErrMsg">
                <xsl:call-template name="makeErrorDiv"/>
            </xsl:if>
        </td>


<xsl:template name="makeErrorDiv">      
        <div style="display:none;">
            <xsl:choose>
                <xsl:when test="descendant::*[ParentId]">
                    <xsl:attribute name="id"><xsl:value-of select="descendant::ParentId[position() = 1]"/><![CDATA[$err]]></xsl:attribute>
                </xsl:when>         
                <xsl:when test="descendant::*[ErrMsg][Name]">
                    <xsl:attribute name="id"><xsl:value-of select="descendant::*[ErrMsg][position() = 1]/Name"/><![CDATA[$err]]></xsl:attribute>
                </xsl:when>
                <xsl:when test="not(descendant::*[ErrMsg])">
                    <xsl:variable name="name"><xsl:value-of select="descendant::*[Name][position() = 1]/Name"/></xsl:variable>
                    <xsl:variable name="parsed"><xsl:value-of select="substring-before($name, '!')"/></xsl:variable>
                    <xsl:attribute name="id"><!--error here! -->
                        <xsl:choose>
                            <xsl:when test="$parsed = ''"><xsl:value-of select="$name"/></xsl:when>
                            <xsl:otherwise><xsl:value-of select="$parsed"/></xsl:otherwise>
                        </xsl:choose>
                    <xsl:text><![CDATA[$err]]></xsl:text></xsl:attribute>   
                </xsl:when>
                <xsl:when test="descendant::*[ErrMsg][not(Name)]">
                    <xsl:variable name="name"><xsl:value-of select="descendant::*[Name][position() = 1]/Name"/></xsl:variable>
                    <xsl:variable name="parsed"><xsl:value-of select="substring-before($name, '!')"/></xsl:variable>
                    <xsl:attribute name="id">
                        <xsl:choose>
                            <xsl:when test="$parsed = ''"><xsl:value-of select="$name"/></xsl:when>
                            <xsl:otherwise><xsl:value-of select="$parsed"/></xsl:otherwise>
                        </xsl:choose>
                    <xsl:text><![CDATA[$err]]></xsl:text></xsl:attribute>                   
                </xsl:when>
            </xsl:choose>   
            <span style="color: #FF0000; font-family: Arial, Helvetica, sans-serif; font-size: 10px; font-weight: bold; text-decoration: none;"><xsl:value-of select="descendant::ErrMsg[position() = 1]"/></span>
        </div>      
    </xsl:template>

XML 示例...不确定是否有用...整个 XML 文件有 1000 多行

<DisclosureRowColor template="OneColumn" position="8" lastPosition="30" colCount="4" color1="#F2F8FE" color2="#ffffff">
                <Cell colspan="1">
                    <ListBox onchange="toggleAddressByAjax();">
                        <Name>APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!YLI</Name>
                        <Size>1</Size>
                        <Default rtexprvalue="true">mb.getValue("APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!YLI", "A")</Default>
                        <Map rtexprvalue="true">mb.getGenericLookup("V_YEAR")</Map>
                        <ReadOnly rtexprvalue="true">mb.isReadonly(2)</ReadOnly>
                    </ListBox>
                    <Label class="sTGBFBS">
                        <Caption> &amp;nbsp;&amp;nbsp;Jahre </Caption>
                    </Label>
                    <ListBox onchange="toggleAddressByAjax();">
                        <Name>APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!MLI</Name>
                        <Size>1</Size>
                        <Default rtexprvalue="true">mb.getValue("APPLICATION_CUSTOMER.EMPLOYED_SINCE_MM!MLI", "A")</Default>
                        <Map rtexprvalue="true">mb.getGenericLookup("V_MONTH")</Map>
                        <ReadOnly rtexprvalue="true">mb.isReadonly(2)</ReadOnly>
                    </ListBox>
                    <Label class="sTGBGBS">
                        <Caption> &amp;nbsp;&amp;nbsp;Monate </Caption>
                    </Label>
                    <ErrMsg/>
                </Cell>
            </DisclosureRowColor>

【问题讨论】:

  • XSLT 有问题。 (最有可能放置一个xsl:attribute。)你能发布XSLT 吗?
  • 同上 DevNull 所说的。您可能在发出文本或元素后尝试使用xsl:attribute 发出节点。您以前可能使用过不同的 XSLT 处理器,它不会抱怨这些事情。发布您的 XSLT,我们将帮助您发现问题。它应该是可以修复的。
  • 大家好,我刚刚添加了源代码...
  • 而不是&lt;xsl:variable name="..."&gt;&lt;xsl:value-of select="..."/&gt;&lt;/xsl:variable&gt;,您可以试试&lt;xsl:variable name="..." select="..." /&gt; 看看是否会改善问题?
  • @IanRoberts 你的意思是为此代码 sn-p 或仅针对违规范围?

标签: html xslt weblogic weblogic12c


【解决方案1】:

认为您的问题可能是您的&lt;xsl:attribute&gt; 元素内的&lt;xsl:text&gt; 节点

<xsl:text><![CDATA[$err]]></xsl:text></xsl:attribute>

我觉得应该这么说

<![CDATA[$err]]></xsl:attribute>

因为您创建的是属性,而不是文本节点。

更新: 我试图重现该错误,但无法重现。但是,我确实发现撒克逊人在属性中使用了空格。您可能想尝试去掉一些 XSL 元素之间的一些空白。

<xsl:when test="not(descendant::*[ErrMsg])">
                <xsl:variable name="name"><xsl:value-of select="descendant::*[Name][position() = 1]/Name"/></xsl:variable>
                <xsl:variable name="parsed"><xsl:value-of select="substring-before($name, '!')"/></xsl:variable>
                <xsl:attribute name="id"><xsl:choose>
                        <xsl:when test="$parsed = ''"><xsl:value-of select="$name"/></xsl:when>
                        <xsl:otherwise><xsl:value-of select="$parsed"/></xsl:otherwise>
                    </xsl:choose><xsl:text><![CDATA[$err]]></xsl:text></xsl:attribute>   
            </xsl:when>

这可能会解决您看到的实际错误:

  <div style="display:none;"><xsl:choose>

我认为必须先将一些文本添加到您的 'div' 元素中,然后才能添加 id 属性。

【讨论】:

  • 你把它从这两个地方都删除了吗?出现了 2 次。此外,您可能想尝试删除每个“何时”元素以缩小问题所在。
  • 是的,在 XSLT 期间,XSLT 处理器指出它在这一行 &lt;xsl:attribute name="id"&gt;&lt;!--error here! --&gt;
  • 哦,我只在stackoverflow中添加了&lt;!--error here--&gt;,以帮助指出错误的具体行。
  • 我玩弄了有问题的条件 &lt;xsl:when test="not(descendant::*[ErrMsg])"&gt; 并将其更改为 &lt;xsl:when test="not(descendant::*[ErrMsg][Name])"&gt; 并且错误消失了......但我不知道可能会对遗留代码产生什么负面影响。
  • 我复制并粘贴了您的解决方案,它成功了!那么为什么空格会导致问题,是否有任何文档可以查找?谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-31
  • 2020-11-03
  • 1970-01-01
  • 2021-06-14
  • 2014-12-05
相关资源
最近更新 更多