XSL:如何最好地将节点存储在变量中,然后在未来的 xpath 表达式中使用它? [英] XSL: How best to store a node in a variable and then use it in future xpath expressions?

查看:20
本文介绍了XSL:如何最好地将节点存储在变量中,然后在未来的 xpath 表达式中使用它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要能够将节点集存储在变量中,然后对其执行更多过滤/排序.我见过的所有示例都涉及使用 XSL2 或扩展,这两者都不是真正的选择.

I need to be able to store a node set in variable and then perform more filting/sorting on it afterward. All the examples I've seen of this involve either using XSL2 or extensions neither of which are really an option.

我的 XML 文档中有一个酒店列表,可以对其进行排序/过滤,然后一次翻 5 个.我发现虽然我重复了很多逻辑,因为目前我还没有找到一种将节点集存储在 xsl 变量中的好方法,然后在它们上使用 xpath 进行进一步的过滤/排序.

I've a list of hotels in my XML doc that can be sorted/filtered and then paged through 5 at a time. I'm finding though I'm repeating alot of the logic as currently I've not found a good way to store node-sets in xsl variable and then use xpath on them for further filtering/sorting.

这就是我所追求的(原谅我头顶写的代码,所以可能不是 100%):

This is the sort of thing I'm after (excuse the code written of the top of my head so might not be 100%):

<xsl:variable name="hotels" select="/results/hotels[active='true']" />
<xsl:variable name="3_star_or_less" select="/results/hotels[number(rating) <= 3]" />
<xsl:for-each select="3_star_or_less">
  <xsl:sort select="rating" />
</xsl:for-each>

有没有人有一个例子来说明如何最好地做这种事情?

Has anyone got an example of how best to do this sort of thing?

推荐答案

试试这个例子:

<xsl:variable name="hotels" select="/results/hotels[active='true']" />
<xsl:variable name="three_star_or_less"
              select="$hotels[number(rating) &lt;= 3]" />
<xsl:for-each select="$three_star_or_less">
    <xsl:sort select="rating" />
    <xsl:value-of select="rating" />
</xsl:for-each>

这篇关于XSL:如何最好地将节点存储在变量中,然后在未来的 xpath 表达式中使用它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆