XSLT是否有一个数组中的任何概念? [英] Does XSLT have any concept of an array?

查看:357
本文介绍了XSLT是否有一个数组中的任何概念?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从来没有真正使用过XSLT和正在寻找一些建议。

I have never really used XSLT before and am looking for some advice.

我从GSA框中XML返回以下项目:

I have the following items returned in XML from GSA box:

<MT N="searchCategories" V="Category 1"/>
<MT N="searchCategories" V="Category 2"/>
etc etc

有可在这些类别的任何量。

There can be any amount of these categories.

我只是想知道,如果XSLT有一个数组的任何概念?

I am just wondering if XSLT has any concept of an array?

如果这样:


  • 我怎么能列举上述所有节点到一个数组?

  • 我该如何获得数组的长度?

如果不是:


  • 是否有任何变通可用?

我相信我使用XSLT 1.0

I believe I am using XSLT version 1.0

推荐答案

正如@迈克尔凯解释说,有两个由用于XPath 1.0和XPath 2.0 XPath数据模型(XDM)不支持任何阵列。

As explained by @Michael Kay, there is no array data structure supported by the XPath data model (XDM) both for XPath 1.0 and XPath 2.0.

然而,也可以使用这样的阵列状语法:

However, it is possible to use an array-like syntax like this:

在XPath 1.0 / 2.0可以定义一个变量包含特定的节点集的这些可以通过自己的位置被访问(按文档顺序),指定在predicate这个位置

In XPath 1.0/2.0 one can define a variable to contain a specific set of nodes and these can be accessed by their position (in document order), specifying this position in a predicate.

下面是一个例子

<xsl:variable name="vTransfers" select="/*/transfer"/>

定义了一个名为变量 vTransfers 同值的节点,设置所有转移元素,每个都是一个孩子XML文档的顶级元素的。

defines a variable named vTransfers with value the node-set of all transfer elements each of which is a child of the top element of the XML document.

然后

$vTransfers[1]

选择包含在 $ vTransfers 的第一个元素。

$vTransfers[2]

选择包含在 $ vTransfers ...

$vTransfers[position() = $k]

选择从 $ vTransfers ,其位置的节点,在文档顺序,等于包含变量中的值 $氏/ code>。

selects the node from $vTransfers whose position, in document order, is equal to the value contained in the variable $k.

此外的XPath 2.0支持 序列的概念的。序列是类似物品的列表。一个项目可以是任何类型的 - 不仅节点。在一个序列中的项目出现的方式订购(定义)的顺序读取。如果在一个序列中的两个项目的节点,其顺序是仍然序列中的定义,这可能是从他们的文档顺序不同。

In addition XPath 2.0 supports the concept of sequences. A sequence is like a list of items. An item can be of any type -- not only node. The items in a sequence are ordered in the way they appear (are defined) in the sequence. If two items in a sequence are nodes, their order is still that defined in the sequence and this may be different from their document order.

示例

<xsl:variable name="vNumList" as="xs:integer*" select="3, 5, 7"/>

那么,当这样的引用:

then when referenced like this:

$vNumlist[2]

生产:

5

记住:虽然这些synthactic结构从数组类似于一个项目的选择,节点集和序列的的阵列。特别是,他们通常缺乏非常快速存取的O(1),该阵列具有其元素。在的节点集的情况下和序列在随机位置访问的项的效率通常为O(N)。这意味着一个算法是O(N)使用数组时,可能是O(N ^ 2)使用带节点集或序列类似数组的符号时。

Remember: Although these synthactic constructs resemble selection of an item from an array, node-sets and sequences are not arrays. In particular, they typically lack the very fast access O(1) that an array has to its elements. In the case of node-sets and sequences the efficiency of accessing an item at a random position is typically O(N). This means that an algorithm that is O(N) when using an array, may be O(N^2) when using the array-like notations with node-sets or sequences.

这篇关于XSLT是否有一个数组中的任何概念?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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