Filtering xml based on attribute presence

5 views
Skip to first unread message

Johni

unread,
Sep 5, 2011, 11:41:09 AM9/5/11
to XSLT
Unable to find the solution myself... I found a lot of examples but I
failed to adapt them for me.
I want to keep xml nodes which have a specific attribute.
For example :
<root>
<section name="A" admin="1">
<section name="Aa">
<bla />
</section>
<section name="Ab">
<ble />
</section>
</section>
<section name="B">
<section name="Ba" admin="1">
<bli />
</section>
<section name="Bb">
<blo />
</section>
</section>
<root>

(note that a section can contain a section and so on)

What I expect :

<root>
<section name="A" admin="1">
<section name="Aa">
<bla />
</section>
<section name="Ab">
<ble />
</section>
</section>
<section name="B">
<section name="Ba" admin="1">
<bli />
</section>
</section>
<root>

I succeeded to do keep nodes which don't have the admin attribute :

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<xsl:template match="//*[@admin='1']">
</xsl:template>

</xsl:stylesheet>

BUT not to keep nodes that HAVE the admin attribute (silly, no ?).

Thanks for helping.

Reply all
Reply to author
Forward
0 new messages