I want to identify xml nodes that does not have specific attribute. Below is the sample xml. I want to retrieve nodes that does have the "response" attribute. I found atricles that help identify node that has a specific attribute but not my requirement.

<top node>
<viewentry position=1 children = 2>
</viewentry>
<viewentry position=1.1 children = 1 response=true>
</viewentry>
<viewentry position= 1.1.1 response=true>
</viewentry>
<viewentry position=2 children=1>
</viewentry>
<viewentry position=2.1 response=true>
</viewentry>
</top node>

xml rules
so must xml

<?xml version="1.0"?>
<topnode>
    <viewentry position="1" children="2">
    </viewentry>
    <viewentry position="1.1" children="1" response="true">
    </viewentry>
    <viewentry position=" 1.1.1" response="true">
    </viewentry>
    <viewentry position="2" children="1">
    </viewentry>
    <viewentry position="2.1" response="true">
    </viewentry>
</topnode>

xpath

xpath is the way
attribute is addressed using @

to start i using xsl

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes" method="xml"/>

    <xsl:template match="/">
        <root>
            <xsl:apply-templates select="topnode/viewentry"/>
        </root>
    </xsl:template>
    <xsl:template match="viewentry">
        <data>has @response</data>
    </xsl:template>
    <xsl:template match="viewentry[not(@response)]">
        <not></not>
    </xsl:template>
</xsl:stylesheet>

result

<?xml version='1.0' ?>
<root>
  <not/>
  <data>has @response</data>
  <data>has @response</data>
  <not/>
  <data>has @response</data>
</root>

Edited 2 Years Ago by xml_looser

This question has already been answered. Start a new discussion instead.