I need to clean up a large XML file after localization. The segments that did not need to be translated were replaced with a placeholder and then in the output were replaced with nothing. However, the surrounding tags remained as regexing all potential tags surrounding those now-missing content appeared to be too complex and dirty too.
When a transformation scenario is applied, there are a lot of blank tables, lines, etc. that are remnant XML elements of the deleted content. I need all those empty tags and their empty children too to go regardless whether they have attributes or not. I was able to find the following solution, however it does mention that it will only work for only elements without attributes without taking care of the elements with children (also empty). What adjustments are required for it to work for all empty elements even with attributes containing values? Any ideas would be appreciated.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="*[descendant::text() or descendant-or-self::*/@*[string()]]">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="@*[string()]">
<xsl:copy/>
</xsl:template>
</xsl:stylesheet>