关于xml:xsl:for-each测试通配符元素

xsl:for-each test a wildcard element

我试图遍历一些XML,直到找到包含文本字符串的元素。

举一个非常简单的XML示例。

1
2
3
4
5
6
7
8
9
10
<document>
  <item>
   <thing1>Fee</thing1>
   <thing2>Fi</thing2>
   <thing3>Fo</thing3>
   <some blah="Thingy">Fum</some>
   I Smell</another>
   <other>Someone</other>
  </item>
</document>

我希望能够搜索包含"事物"的任何元素,我之前已经看过使用诸如...这样的属性来完成此操作...

1
<xsl:for-each test="contains(@blah,'Thingy')"></xsl:for-each>

但是我想搜索" thing1,thing2,thing3",然后获取它们的<xsl:value-of select"." />,它们分别是Fee,Fi和Fo。我需要排除其他元素,因为它们将不包含字符串" thing"


尝试:

1
<xsl:for-each select="*[contains(name(), 'thing')]">

或者,以更好地适应给定的示例:

1
<xsl:for-each select="*[starts-with(name(), 'thing')]">

两者均从item的上下文中调用。