Removing empty nodes from the RESULTING xslt transformation -


i have following requirement, need exclude <xlink:link> if it's href attribute-, , <loc> if it's value ends ".xml" | ".xslt" | ".properties". leaves me following. <div ...></div> there way remove these <div ...></div> in 1 go, or there need consecutive processing?

fragment of input:

<?xml version="1.0" encoding="utf-8" standalone="no"?> <urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml">     <url>         <loc id="843">en-us/system/xml/navigation.xml</loc>         <xhtml:link href="/fr-fr/system/xml/navigation.xml" hreflang="fr-fr" rel="alternate"/>         <xhtml:link href="/en-uk/system/xml/navigation.xml" hreflang="en-uk" rel="alternate"/>     </url>     <url>         <loc id="3159">/en-us/index.html</loc>         <xhtml:link href="/fr-lu/index.html" hreflang="fr-lu" rel="alternate"/>     </url> </urlset> 

my xslt:

<xsl:stylesheet version="2.0" xpath-default-namespace="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsl="http://www.w3.org/1999/xsl/transform" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1" xmlns:xhtml="http://www.w3.org/1999/xhtml" exclude-result-prefixes="video image xsl xhtml"> <xsl:output method="xhtml" indent="yes" omit-xml-declaration="yes"/> <xsl:strip-space elements="*"/>  <!-- identity transform --> <xsl:template match="@*|node()">     <xsl:copy copy-namespaces="no">         <xsl:apply-templates select="@*|node()" />     </xsl:copy> </xsl:template>  <!-- transform urlset --> <xsl:template match="urlset">     <div class="urlset"><xsl:apply-templates select="@*|node()" /></div> </xsl:template>  <!-- transform url --> <xsl:template match="url">     <div class="url"><xsl:apply-templates select="@*|node()" /></div> </xsl:template>    <!-- transform 'link' when valid --> <xsl:template match="xhtml:link">     <a><xsl:apply-templates select="@*|node()" /></a> </xsl:template>   <!-- transform 'loc' when valid --> <xsl:template match="loc">     <a>         <xsl:attribute name="href">             <xsl:value-of select="." />         </xsl:attribute>         <xsl:apply-templates select="@*" />     </a> </xsl:template>   <!-- transform 'link' when not valid --> <xsl:template match="xhtml:link[@href[ends-with(.,'.xml') or ends-with(.,'.xslt') or ends-with(.,'.properties')]]" />   <!-- transform 'loc' when not valid --> <xsl:template match="loc[ends-with(.,'.xml') or ends-with(.,'.xslt') or ends-with(.,'.properties')]" />  </xsl:stylesheet> 

result:

<div class="urlset">    <div class="url"></div>  <=== *** need rid of likes of ***    <div class="url">       <a href="/en-us/index.html" id="3159"></a>       <a href="/fr-lu/index.html" hreflang="fr-lu" rel="alternate"></a>    </div> 

i've done searching similar questions addressing removal of empty nodes original document, not resulting one.

any appreciated.

if add

<xsl:template match="url[every $node in (loc, xhtml:link/@href) satisfies (ends-with($node,'.xml') or ends-with($node,'.xslt') or ends-with($node,'.properties'))]"/> 

then url elements have loc , xhtml:link/@href endings want remove not transformed , not create output. approach can in 1 step, don't know whether there can other content foo elements present in url require element transformed, can write more complex conditions cover that.


Comments