Re: [xsl] remove certain elements but keep children

Subject: Re: [xsl] remove certain elements but keep children
From: Anton Triest <anton@xxxxxxxx>
Date: Mon, 04 Oct 2004 12:02:16 +0200
Hi Ben,

You could do an identity transform to copy all elements except 'output':

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" version="1.0" indent="yes"/>
<xsl:strip-space elements="*"/>
<!-- identity transform: copy all elements -->
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
<!-- override 'output' elements (copy its children) -->
<xsl:template match="output">
<xsl:apply-templates select="*"/>
</xsl:template>
</xsl:stylesheet>


Cheers,
Anton


Ben Munat wrote:


Hello,

I'm writing an app that aggregates html into a single doc. The chunks of html are put into the new document wrapped in "output" tags. These output tags can be intermingled with html tags.

I'm trying to come up with an xpath or xsl template(s) that will remove the output tags, while leaving their child html and without producing duplicate content.

Here's an example doc:

<output>
    <div>
        <output>
            <h1>a header</h1>
            <p>some stuff</p>
            <output>
                <div>
                    <p>foo bar</p>
                </div>
            </output>
            <p>more html</p>
        </output>
    </div>
    <p>some html</p>
</output>

And I want it to be:

<div>
    <h1>a header</h1>
    <p>some stuff</p>
        <div>
            <p>foo bar</p>
        </div>
        <p>more html</p>
</div>
<p>some html</p>


Any ideas?


thanks,

Ben

Current Thread