Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/xslt/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
基于元素名子字符串的XSLT节点选择_Xslt - Fatal编程技术网

基于元素名子字符串的XSLT节点选择

基于元素名子字符串的XSLT节点选择,xslt,Xslt,如何使用XSLT根据节点元素名的子字符串选择节点 例如,考虑XML: <foo_bar>Keep this. <foo_who>Keep this, too. <fu_bar>Don't want this.</fu_bar> </foo_who> </foo_bar> 保留这个。 这个也留着。 我不想要这个。 我想从中输出: <foo_bar>Keep this. <foo_who

如何使用XSLT根据节点元素名的子字符串选择节点

例如,考虑XML:

<foo_bar>Keep this.
  <foo_who>Keep this, too.
    <fu_bar>Don't want this.</fu_bar>
  </foo_who>
</foo_bar>
保留这个。
这个也留着。
我不想要这个。
我想从中输出:

<foo_bar>Keep this.
  <foo_who>Keep this, too.
  </foo_who>
</foo_bar>
保留这个。
这个也留着。
在这里,我想选择用于处理名称与“foo.*”等正则表达式匹配的节点

我想我需要一个XSLT模板匹配属性表达式,或者一个应用模板选择属性表达式,将正则表达式应用于元素的名称。但是,如果没有像语句这样的构造,这可能无法实现


任何帮助都将不胜感激。

以下是一些XSL,它可以找到以“foo”开头的元素,帮助您开始使用。我认为直到XSLT2.0基于时才添加正则表达式功能


它给出了这个输出,似乎有一个额外的换行符

<foo_bar>Keep this.
  <foo_who>Keep this, too.

  </foo_who>
</foo_bar>
保留这个。
这个也留着。

在查看OP的输入时,我建议“以($name,'foo_')开头”,否则就是这样+1--可以通过在的帮助下不复制以下同级::text()节点来防止额外的换行。
<foo_bar>Keep this.
  <foo_who>Keep this, too.

  </foo_who>
</foo_bar>