Hi,
I need to remove some lines from an XML file is the value within a tag is empty.
Imagine this scenario,
<acd><acdID>2</acdID><logon></logon></acd>
<acd><acdID></acdID><logon></logon></acd>
<acd><acdID></acdID><logon></logon></acd>
<acd><acdID></acdID><logon></logon></acd>
I need to remove the last 3 lines because the value between <acdID></acdID> is empty, the first line is valid because of the 2
Many Thanks,
Giles
zaxxon
2
grep -v '<acdID></acdID>' infile
man, easy when you know how!
Legend
if you need to remove the empty elements using a stylesheet, here is one way of doing it
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" />
<xsl:strip-space elements="*" />
<xsl:template match="*">
<xsl:copy>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<xsl:template match="acd">
<xsl:if test="acdID/node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:if>
<xsl:if test="not(acdID/node())">
</xsl:if>
</xsl:template>
</xsl:stylesheet>