Hi Jem!
Your problem already have been resolved (see Jeni, Stuart and Morrow's
replies) and they work with your example, but, has Stuart said, it only
work with the first <record type="continue">.
with a little change on Jeni's template it could work on every
following-sibling <record type="continue">.
heres is the xsl:
<xsl:template match="records">
<xsl:apply-templates select="record[@type = 'normal']" />
</xsl:template>
<xsl:template match="record[@type = 'normal']">
<record>
<xsl:copy-of select="*" />
<xsl:apply-templates select="following-sibling::record[1][@type =
'continuation']"/>
</record>
</xsl:template>
<xsl:template match="record[@type = 'continuation']">
<xsl:copy-of select="*" />
<xsl:apply-templates select="following-sibling::record[1][@type =
'continuation']"/>
</xsl:template>
hope that this helps you
-----Original Message-----
From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
[mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Jem Clear
Sent: Tuesday, August 20, 2002 10:42 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: How to output partial elements?
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
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|