作者:君莫笑 | 来源:互联网 | 2023-10-10 19:14
I have an XML document with several
elements, each of which contains the
of the person, and several
elements inside a grouping
element.
我有一个带有几个
元素的XML文档,每个元素都包含person的
,以及分组
元素中的几个
元素。
I already found that to obtain the greatest
I have to do an
with a
inside it and then take the first element, as XSLT v1.0 doesn't have fn:max()
.
我已经发现要获得最大的
我必须在其中使用
执行
,然后获取第一个元素,因为XSLT v1.0没有FN:MAX()。
But I guess that this would give me the greatest value from all. So, how could I arrange a stylesheet to extract each person's
with their greatest
?
但我想这会给我最大的价值。那么,我怎样才能安排样式表来提取每个人的
及其最大的
?
2 个解决方案
2
One can use the "maximum" template as provided by FXSL -- the Functional Programming Library for XSLT. FXSL is written entirely in XSLT itself.
可以使用FXSL提供的“最大”模板 - XSLT的功能编程库。 FXSL完全用XSLT编写。
Here is an example of using the "maximum" template:
以下是使用“最大”模板的示例:
When this transformation:
当这个转变:
1
0
is applied on this XML document:
应用于此XML文档:
01
02
03
04
05
06
07
08
09
10
the wanted result is obtained.
获得想要的结果。
10
Note, that I can pass any needed "compare" operation as parameter! For example, if my compare operation returns 1 whenever $arg1 <$arg2, then the above transformation will produce "01" -- the minimum of all values.
注意,我可以将任何需要的“比较”操作作为参数传递!例如,如果我的比较操作在$ arg1 <$ arg2时返回1,那么上面的转换将产生“01” - 所有值的最小值。
Now, I will show two solutions for the original problem.
现在,我将针对原始问题展示两种解决方案。
Solution1 (using FXSL's "maximum" template):
1
0
When this transformation is applied on the following XML document:
将此转换应用于以下XML文档时:
8
10
4
12
2
11
15
6
10
44
9
the wanted result is produced:
产生了想要的结果:
12
15
44
Solution2 (using a template written by hand):
When this transformation:
当这个转变:
-99999999999999999999
is applied on the same XML document, again the correct result is produced:
应用于同一XML文档,再次生成正确的结果:
12
15
44