[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] How to output partial elements?


Subject: [xsl] How to output partial elements?
From: Jem Clear <jem@xxxxxxxxxxxxxx>
Date: Tue, 20 Aug 2002 10:42:07 +0100

I have been bashing my brain for days over this and I need help.
Here is the (style of) input I have:

  <record n="1" type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
    <bar> <things> ... </things> </bar>
  </record>
  <record n="2" type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
  </record>
  <record n="3" type="continuation">
    <bar> <things> ... </things> </bar>
  </record>
  <record n="4" type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
    <bar> <things> ... </things> </bar>
  </record>

The problem is <record>s 2 and 3: they need to be concatenated. (The 'n'
attribute is irrelevant: I only put it there for easy reference in
illustration.)

At first I thought this was easy: 

   have a template to match <record>
   if (@type != "continuation") {
     write "</record>" to the output
   }
   write "<record>" to output
   copy all child nodes to output   

But XSLT won't allow partial (malformed) XML to be written to the
output tree from a <xsl:template> -- so I can't do this!
*Everyone* tells me XSLT is "the right tool" for this sort of task:
but if I'd followed my natural inclination and hacked it up in Perl
it'd be trivial to chop the offending two lines out! :)

Any ideas how to make the output look like this:

  <record type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
    <bar> <things> ... </things> </bar>
  </record>
  <record type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
    <bar> <things> ... </things> </bar>
  </record>
  <record type="normal">
    <foo> <x>... <y>...</y> ...</x> </foo>
    <bar> <things> ... </things> </bar>
  </record>

Thanks

Jem Clear
29 School Road, Moseley, Birmingham, B13 9TF, UK
Tel & Fax: +44 (0)121 689 3637
Email:     jem@xxxxxxxxxxxxxx


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



Current Thread
Keywords