Reputation: 135
I am trying to loop through some XML until I find an element that contains a string of text.
take a very simple XML example.
<document>
<item>
<thing1>Fee</thing1>
<thing2>Fi</thing2>
<thing3>Fo</thing3>
<some blah="Thingy">Fum</some>
<another>I Smell</another>
<other>Someone</other>
</item>
</document>
I want to be able to search through for any element/s that contains "thing", I have seen this done before with an attribute like so...
<xsl:for-each test="contains(@blah,'Thingy')"></xsl:for-each>
but I want to search the "thing1, thing2, thing3" and then obtain their <xsl:value-of select"." />
which will be Fee, Fi, and Fo. I need to exclude the other elements as they aren't going to contain the string "thing"
Upvotes: 0
Views: 816
Reputation: 116993
Try:
<xsl:for-each select="*[contains(name(), 'thing')]">
or, to better fit the given example:
<xsl:for-each select="*[starts-with(name(), 'thing')]">
Both to be called from the context of item
.
Upvotes: 1