我想选择具有值属性大于阈值的值属性的所有记录 . 我在 $dataset
中的数据如下所示:
<component name="Information Technology" value="5712"/>
<component name="NADCO" value="5033"/>
<component name="Electronic Security" value="2104"/>
<component name="SATT" value="1608"/>
<component name="E-Business Office" value="291"/>
<component name="Systems Development" value="158"/>
<component name="Test" value="694"/>
我还有 $threshold
,其值为 4000
. 我用来获取值大于4000的组件的代码是:
<xsl:variable name="records" select="$dataset/self::node()[@value > $threshold]"/>
所以我希望 records
是组件 Information Technology
和 NADCO
的列表,但变量是空的 . 我哪里做错了?
ps注意我没有根节点
EDIT
生成数据集的代码如下
<xsl:variable name="dataset" select="$components/component" />
$components
是
<components>
<component name="Information Technology" value="5712"/>
<component name="NADCO" value="5033"/>
<component name="Electronic Security" value="2104"/>
<component name="SATT" value="1608"/>
<component name="E-Business Office" value="291"/>
<component name="Systems Development" value="158"/>
<component name="Test" value="694"/>
</components>
1 回答
我是通过以下方式做到的:
dataset
变量包含components/component
(component
标签的集合,正如您所做的那样) .XPath表达式是
$dataset[@value > $threshold]
,即:$dataset
- 变量(记录容器) .[@value > $threshold]
- 谓词 .如你所见,甚至不需要
self::node()
.所以匹配
main
(root)标签(containsigcomponents
)的整个示例模板如下所示:它甚至可以在1.0 / Xalan版本中运行 . 有关工作示例,请参阅http://xsltransform.net/nb9MWsz