|
Subject: RE: Flattening a tree From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx> Date: Fri, 14 Jul 2000 16:09:45 +0100 |
Pierre,
>However, the first solution is not flat enough and the second one is too
>flat !
Erm - it was all supposed to be one solution. Sorry I didn't make that
clearer. Using your input:
---- test.xml ----
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<document>
<para>
content-1
<List>
<Item>content-2</Item>
<Item>content-3</Item>
</List>
content-4
<graphic/>
content-5
</para>
</document>
----
With the following stylesheet:
---- test.xsl ----
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="*" mode="flatten">
<xsl:choose>
<xsl:when test="*"><xsl:apply-templates mode="flatten" /></xsl:when>
<xsl:otherwise>
<xsl:copy-of select="." />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="text()" mode="flatten">
<xsl:if test="normalize-space(.) != ''">
<xsl:element name="{name(..)}">
<xsl:value-of select="normalize-space(.)" />
</xsl:element>
</xsl:if>
</xsl:template>
<xsl:template match="document">
<document>
<xsl:apply-templates mode="flatten" />
</document>
</xsl:template>
</xsl:stylesheet>
----
Gives the output:
---- out.xsl ----
<?xml version="1.0"?>
<document>
<para>content-1</para>
<Item>content-2</Item>
<Item>content-3</Item>
<para>content-4</para>
<graphic/>
<para>content-5</para>
</document>
----
Which is what you said you wanted. This was using SAXON.
I hope that works for you now,
Jeni
Dr Jeni Tennison
Epistemics Ltd, Strelley Hall, Nottingham, NG8 6PE
Telephone 0115 9061301 ? Fax 0115 9061304 ? Email
jeni.tennison@xxxxxxxxxxxxxxxx
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
| Current Thread |
|---|
|
| <- Previous | Index | Next -> |
|---|---|---|
| RE: Flattening a tree, Pierre-Yves Saumont | Thread | RE: Flattening a tree, Pierre-Yves Saumont |
| Re: One XSL combining to different , SoftLiban DACCACHE W | Date | Re: One XSL combining to different , SoftLiban DACCACHE W |
| Month |