[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

RE: Flattening a tree

Subject: RE: Flattening a tree
From: Jeni Tennison <Jeni.Tennison@xxxxxxxxxxxxxxxx>
Date: Fri, 14 Jul 2000 16:09:45 +0100
jeni tennison tree
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.