XSLT-选择以下项目直到特定标签 [英] XSLT-select following items until particular tag

查看:35
本文介绍了XSLT-选择以下项目直到特定标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑我有这个 XML 文件:

<w>约翰</w><x>史密斯</x><z>安迪</z><w>咕</w><w>约瑟夫</w><y>李</y><x>肯尼</x><z>玛丽亚</z><y>佐伊</y><z>马丁</z>

现在我希望在 1st 2nd <之间选择元素/p>

所以输出将是:

 <w>Goo</w><w>约瑟夫</w><y>李</y><x>肯尼</x>

我所知道的是我们可以copy-of"选择z[1]"的以下兄弟姐妹"但我不知道如何在 "z[2]" 上停止它

解决方案

选择以下两个节点集的交集:

  • 第一个 z
  • 之后的所有节点
  • 第二个z
  • 之前的所有节点

这两个集合的交集将是第一个和第二个 z 元素之间的所有节点.使用以下表达式:

/*/z/following-sibling::*[count(.|/*/z[2]/preceding-sibling::*) =计数(/*/z[2]/preceding-sibling::*)]

注意:这使用 Kayessian 节点集交集公式.一般情况下,使用以下方法求$set1$set2的交集:

$set1[count(.|$set2)=count($set2)]

Consider I have this XML file:

<text>
  <w>John</w>
  <x>Smith</x>
  <z>Andy</z>
  <w>Goo</w>
  <w>Joseph</w>
  <y>Lee</y>
  <x>Kenny</x>
  <z>Maria</z>
  <y>Zoe</y>
  <z>Martin</z>
</text>

Now I wish to select elements between 1st <z> and 2nd <z>

So the output will be :

  <w>Goo</w>
  <w>Joseph</w>
  <y>Lee</y>
  <x>Kenny</x>

What I know is we can "copy-of" select the "following siblings" of "z[1]" but I don't know how to stop it on "z[2]"

解决方案

Select the intersection of the following two node-sets:

  • All nodes after the first z
  • All nodes before the second z

The intersection of these two sets will be all nodes between the first and second z elements. Use the following expression:

/*/z/following-sibling::*[
    count(.|/*/z[2]/preceding-sibling::*) =
    count(/*/z[2]/preceding-sibling::*)]

Note: This uses the Kayessian node-set intersection formula. In general, use the following to find the intersection of $set1 and $set2:

$set1[count(.|$set2)=count($set2)]

这篇关于XSLT-选择以下项目直到特定标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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