使用 XSLgenerate-key() 的唯一元素

发布于 2024-10-23 22:33:41 字数 1398 浏览 3 评论 0原文

首先感谢在我之前的帖子中回复的所有人。为了避免混淆,我在这里发布类似的信息,但问题也相应更新。

我的问题是下面所示的 xsl for-each 从未被执行,表明结果集中没有任何内容。但是,我不明白为什么。下面进一步描述。

输入结构

<AllMyResults>
<Result>
<someElement>value</state>
<otherElement>value 2</state>
<subject>Get unique subjects!</state>
</Result>
</AllMyResults>

在我的 XSL 文件顶部,我有关键语句

<xsl:key name="SubjectKey" match="All_Results/Result" use="subject"/>

[2] 我的 XSL 文件的核心内容,它使用不同的输入结构:

<xsl:for-each select="$ResultSet/subject[
                         generate-id()
                          = generate-id(key('SubjectKey', 'subject')[1])
                      ]">
... this point is never reached ...
</xsl:for-each>

输入结构由上面的[2]使用 输入结构只是一个元素列表。

我在这里缺少什么?我使用调试器确定 for-each 从未执行过,这表明表达式 $ResultSet/subject[generate-id() =generate-id(key('SubjectKey', 'subject) 生成的集合')[1])] 是空集。但为什么?

其他信息

$ResultSet 是一个节点集。它是传递给模板的参数。根据我的调试器,“key”语句被执行适当的次数——每次“主题”出现在我的输入文件中一次。根据我读到的关于generate-id()的内容,没有参数,它在当前节点上运行。我还尝试了各种变体,而不是 $ResultSet/subject。 ($ResultSet/*/subject$ResultSet/* 等)

First of all thank you to everyone who replied in my previous thread. In the interest of avoiding confusion I am posting similar information here, but questions updated accordingly.

My problem is that my xsl for-each shown below never gets executed, indicating that there is nothing in the result set. However, I cannot figure out why. Further description below.

Input structure

<AllMyResults>
<Result>
<someElement>value</state>
<otherElement>value 2</state>
<subject>Get unique subjects!</state>
</Result>
</AllMyResults>

At the top of my XSL file I have the key statement

<xsl:key name="SubjectKey" match="All_Results/Result" use="subject"/>

[2] The meat of my XSL file, which uses a different input structure:

<xsl:for-each select="$ResultSet/subject[
                         generate-id()
                          = generate-id(key('SubjectKey', 'subject')[1])
                      ]">
... this point is never reached ...
</xsl:for-each>

Input structure used by [2] above
The input structure is just a list of elements.

What am I missing here? I used a debugger to determine that the for-each was never executed, which indicates that the set generated by the expression $ResultSet/subject[generate-id() = generate-id(key('SubjectKey', 'subject')[1])] was the empty set. But why?

Additional Info

$ResultSet is a node set. It was a parameter passed in to the template. According to my debugger, the "key" statement gets executed the appropriate amount of times -- once per time a "subject" shows up in my input file. According to what I've read about generate-id(), with no params, it operates on the current node. Instead of $ResultSet/subject I've also tried all sorts of variations. ($ResultSet/*/subject, $ResultSet/*, etc)

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

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

发布评论

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

评论(2

随心而道 2024-10-30 22:33:41

我相信应该是 key('SubjectKey', subject),而不是 key('SubjectKey', 'subject') (注意引号)并且谓词应该是在 $ResultSet 上,而不是在 $ResultSet/subject 上:

$ResultSet[generate-id() = generate-id(key('SubjectKey', subject)[1])]

I believe that should be key('SubjectKey', subject), not key('SubjectKey', 'subject') (note the quotes) and that the predicate should be on $ResultSet, not $ResultSet/subject:

$ResultSet[generate-id() = generate-id(key('SubjectKey', subject)[1])]
能否归途做我良人 2024-10-30 22:33:41

您是否尝试过,因为密钥只需要知道它在哪个节点上匹配,而不是 xpath,这似乎就是您正在做的事情。

Have you tried as the key only needs to know what node it is matching on not the xpath, which seems to be what you are doing.

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