Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xpath for matching all text nodes in a document except text nodes in specific elements

Tags:

xml

xslt

xpath

Attemping to build a template in XSLT to match on a specific Xpath case.

In this example XML document I want to match on all the text in the entire document except for in <x>:

<root>
 <tag1> I want this text </tag1>
 <tag2> I want this text </tag2>
 <x> I don't want to match on this text </x>
 <tag3> I want this text </tag3>
</root>

Any ideas on this Xpath? I'm trying to build a template for it to transform my document for this specific case.

What I have come up with some far is something like this that's not working:

<xsl:template match="text()[not(matches(.,x))]">

Any ideas?

like image 548
Avbasot Avatar asked Nov 09 '12 17:11

Avbasot


1 Answers

When you write . it takes the string value of the text node, not the node-name of the parent. And matches needs a string prarameter

You could write it as:

<xsl:template match="text()[not(matches(name(..),'x'))]">

Or better:

<xsl:template match="text()[not(parent::x)]">
like image 108
BeniBela Avatar answered Sep 16 '22 12:09

BeniBela