1
votes

I have a xml file like the one below. I need to select using xslt 1.0 all "name" elements where the paths does not contain the word "fast". In this case I would select /root/name and /root/name/name, but not /root/fast/name.

My original template matcher was

<xslt:template match="/root//name">
    ....
</xslt:template>

This worked but then the "fast" element was added and so my selector broke.

How can I do that in XSLT 1.0? I have been trying multiple ways, but I just can't seem to find a way that would compile and do what I need.

Thank you all.

<root>
    <fast>
        <name>fast/name</name>
    </fast>
    <name>name</name>
    <name>
        <name>name/name</name>
    </name>
</root> 
1

1 Answers

1
votes

You can use this:

if you run on condition with data than

<xsl:template match="/root//name[not(contains(., 'fast'))]">

or if you run on condition with element than

<xsl:template match="/root//name[not(ancestor::fast)]">