dotaneli
dotaneli

Reputation: 45

xsl template matching with text()

I'm trying to use a an xsl:template with the following:

xsl:template match="/a/b/c/d/text() = 'Foo'"

But I get an error from XMLSpy...: Invalid Pattern: Unexcpected token - "= 'Foo'"

Anyone has any idea what i'm doing wrong?

Thanks.

Upvotes: 0

Views: 172

Answers (2)

Mitya
Mitya

Reputation: 34596

<xsl:template match='/a/b/c/d[text() = "Foo"]'>

text() = "Foo" is a comparison, and in XPath this means it must be inside a predicate - in square brackets.

Upvotes: 0

Martin Honnen
Martin Honnen

Reputation: 167716

If you want to match the d elements then use match="/a/b/c/d[. = 'Foo']", if you need to match the text node children of the d elements then use match="/a/b/c/d/text()[. = 'Foo']".

Upvotes: 2

Related Questions