RE: [xsl] Null Values

Subject: RE: [xsl] Null Values
From: "Michael Kay" <mhkay@xxxxxxxxxxxx>
Date: Fri, 30 Mar 2001 10:55:43 +0100
> My requirement is to remove tag names when I convert from one
> xml to another
> xml, if there is no data.
> e.g
> <F1>1234</F1>
> <F2>1234</F2>
> <F3></F3>
> <F4>1234</F4>
>
> to
>
> <F1>1234</F1>
> <F2>1234</F2>
> <F4>1234</F4>
>
It's rather important to learn the correct terminology here, because it will
help you to understand the specs. Talking about "tag names" suggests you're
thinking in terms of the serialized XML rather than its tree structure,
which will get you into all sorts of conceptual confusion.

What you are actually trying to remove is an element node. And in fact you
don't need to remove it, you just need to refrain from copying it.

The way you do this depends on how you are copying the other nodes. If
you're doing it using template rules, the simplest way is to have an
overriding template rule that matches elements with "no data" (which we
might interpret as meaning no child element or text nodes), and does
nothing:

<xsl:template match="*[not(* or text())]" priority="17"/>

Mike Kay
Software AG



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread