为什么generate-id()函数返回相同的id两次?
我有一些不是我编写的 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) > 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题出在您没有向我们展示的代码中。
generate-id()
函数返回参数节点或上下文节点的唯一标识符字符串 。因此,它对于唯一节点来说是唯一的...您可能在具有相同上下文节点的两个内容模板中调用 p/0 函数。这怎么可能?好吧...
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...
call-template
instruction does not change the context node