RE: [xsl] How to output partial elements?

Subject: RE: [xsl] How to output partial elements?
From: Stuart Brown <sbrown@xxxxxxxxxxxxx>
Date: Tue, 20 Aug 2002 11:04:09 +0100
Hi Jem,

> 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.)

What you actually want to do here is to include in a type="normal" record
the children of a subsequent type="continuation" record, so something like
this would be required:

<!-- Limit match to normal records only -->
<xsl:template match="record[@type='normal']">
  <record n="{@n}">
    <!-- Handle the contents of this record -->
    <xsl:apply-templates/>
    <!-- If the first following sibling is a record of type continuation,
handle its children -->
    <xsl:apply-templates
select="following-sibling::record[1][@type='continuation']/*"/>
  </record>
</xsl:template>

This assumes that you only ever have one continuation: if there are
potentially more then the XPath will be more complicated. 

Hope this helps,

Stuart
> 

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


Current Thread