Posts Tagged ‘xslt’

Any XSLT/XPath experts out there? I’m a little bit stuck. I have a stylesheet that is effectively transforming XHTML into XHTML (best not to ask) and is matching any element with select = "xhtml:*". However, sometimes empty a elements creep into the original XHTML and get copied across to the output. These can play havoc with the CSS and JavaScript used on the final web page so I’d like to supress them.

How do I modify the select statement above to select all XHTML elements except for a elements that have either no text node children or have text node children composed solely of white space?

In other words if the input contains <a></a> or <a /> or <a> </a> then it should be skipped (assume for now that any attributes are irrelevant and that we’ll deal with the case where it contains another element node but no text nodes later).

I tried select = "xhtml:*[not(self::a[not(text())])][not(self::a[not(text() = ' ')])]" as a first stab but as well as being very ugly it doesn’t seem to be working. Any ideas?

Tags: ,