XSL 1.0 Empty Element Limitations

I have been working with XSLT quite a bit recently and I have just come to a point where I wanted an XML file to be translated to another XML file with empty elements.

What I had was this: <node att1=“1“ att1=“2“></node>

but what I wanted was this: <node att1=“1“ att2=“2“ />

I had only read XML that I wrote using XmlTextWriter through code and XmlTextWriter does this for you automatically. My reading logic was designed to only read the beginning of a node, then read all attributes. The code had assumed that there was no end element. Of course the easy fix was to just add a quick check after loading all of the attributes (like so):

while(reader.Read())
{
    if (!reader.IsStartElement()) return;

      // blah blah code
    switch(reader.Name)
    {...}

    // the easy cheat (or so i thought)
    if (!reader.HasValue()) reader.Read();
}

I just recently started converting old my old file formats to my new format through XSL and ran into this snag, so I figured I would learn how to do it in XSL rather than 'cheating'. I searched and searched on how to do this with XSL and after 30+ minutes finally found out that you can't. This should have been bold 'in my face' documentation I would have thought, but it wasn't bold enough I guess, because it took me forever to find it.

Print | posted on Monday, July 18, 2005 12:21 AM