为什么generate-id()函数返回相同的id两次?

发布于 2024-10-06 01:58:40 字数 1183 浏览 0 评论 0原文

我有一些不是我编写的 XSLT,但我必须维护它。在某些时候,它使用generate-id()创建一个空的div,然后由脚本进一步操作。问题是该 div 位于另一个 div 内(我原以为这有点毫无意义,但无论如何都是可以接受的)并且两者都被赋予相同的 id!我用 Xalan 尝试过,然后又用 JRE 变压器尝试过,得到了相同的结果。然后我尝试使用 Eclipse/Xalan XSLT 调试器,当我跨过这个东西时,一切都正常工作...

XSLT 看起来像这样:

<xsl:template match="listed">
    <xsl:variable name="showwhat">
        <xsl:call-template name="IdentifyAudience"/>
    </xsl:variable>
    <xsl:if test="string-length($showwhat) &gt; 0">
        <div>
            <xsl:attribute name="id">
                <xsl:value-of select="generate-id()"/>   
            </xsl:attribute>
            <xsl:call-template name="Blah"/>
            <xsl:apply-templates/>
        </div>
    </xsl:if>
</xsl:template>

XML 片段是这样的:

<listed id='ID39AF705AE17A000F337B000A' mode='html'>
    <ul>
        <li>Blah blah</li>
    </ul>
</listed>
<listed id='ID39AF715892AE000F337B002B' mode='html'>
    <ul>
         <li>Blech blech.</li>
    </ul>
</listed>

我意识到这有点复杂 - 任何线索?请?

I have some XSLT that I didn't write but I have to maintain it. At some points it is using generate-id() to create an empty div which is then manipulated by a script further on. Problem is that the div is inside another div (i had thought this was a bit pointless, but acceptable anyway) and both are being given the same id! I tried this with Xalan and then again with the JRE transformer with the same result. I then tried to use the Eclipse/Xalan XSLT debugger and when i am stepping over the thing, it all works correctly...

The XSLT looks like this:

<xsl:template match="listed">
    <xsl:variable name="showwhat">
        <xsl:call-template name="IdentifyAudience"/>
    </xsl:variable>
    <xsl:if test="string-length($showwhat) > 0">
        <div>
            <xsl:attribute name="id">
                <xsl:value-of select="generate-id()"/>   
            </xsl:attribute>
            <xsl:call-template name="Blah"/>
            <xsl:apply-templates/>
        </div>
    </xsl:if>
</xsl:template>

And the XML fragment is like this:

<listed id='ID39AF705AE17A000F337B000A' mode='html'>
    <ul>
        <li>Blah blah</li>
    </ul>
</listed>
<listed id='ID39AF715892AE000F337B002B' mode='html'>
    <ul>
         <li>Blech blech.</li>
    </ul>
</listed>

I appreciate this is a bit complicated - any clues? Please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹎☆浅夏丿初晴 2024-10-13 01:58:40

问题出在您没有向我们展示的代码中。

generate-id() 函数返回参数节点或上下文节点的唯一标识符字符串

因此,它对于唯一节点来说是唯一的...您可能在具有相同上下文节点的两个内容模板中调用 p/0 函数。这怎么可能?好吧...

<xsl:call-template name="Blah"/> 

call-template指令不会更改上下文节点

The problem is in the code you haven't show to us.

generate-id() function return an unique identifier string for argument node or the context node otherwise.

So, it's unique for unique node... You are probably calling the p/0 function in two content template with the same context node. How is this posible? Well...

<xsl:call-template name="Blah"/> 

call-template instruction does not change the context node

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文