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

From "flat" XML To Nested Sections - XSL 2.0

Subject: From "flat" XML To Nested Sections - XSL 2.0
From: Nadia.Swaby@xxxxxx
Date: Tue, 24 May 2005 11:05:40 -0400
flat xml to nested xml
Hello All

I am trying to convert a Framemaker XML Document to an XML Document that
conforms to our custom DTD.  The Frame XML looks something like this:

<XML>
    <TITLE/>
    <Heading-1>
        <A ID="pgfId-1009125"/> CASINGS</Heading-1>
    <Body>
        <A ID="pgfId-1009975"/>  Designer's responsibility</Body>
    <Alpha-FirstList>
        <Alpha-First>
            <A ID="pgfId-1009976"/> vertical is required.</Alpha-First>
        <Alpha-Next>
            <A ID="pgfId-1009987"/> stress.</Alpha-Next>
        <Alpha-Next>
            <A ID="pgfId-1009988"/> Sufficient to avoid such
problems</Alpha-Next>
    </Alpha-FirstList>
    <Heading-2>
        <A ID="pgfId-1012502"/> Applicable Documents</Heading-2>
    <Body>
        <A ID="pgfId-1012503"/> The following publications form a part of
this document to the extent specified herein</Body>
    <Heading-1>
        <A ID="pgfId-1010000"/> NOTE</Heading-1>
    <Body>
        <A ID="pgfId-1010001"/> The | symbol is used to indicate technical
and major editorial  changes</Body>
</XML>

It to be something like this:

<engineering.doc>
   <dm>
      <dm.frontmatter><!---some elements here--></dm.frontmatter>
     <body>
        <section>
           <heading id="pgfId-1009125">CASINGS</heading>
          <para>Designer's responsibility</para>
          <!---list in here--->
          <section>
             <heading id="pgfId-1012502">Applicable Documents</heading>
            <para>The following publications form a part of this document
to the extent specified herein</para>
          </section>
       </section>
       <section>
          <heading id="pgfId-1010000">NOTE</heading>
          <para>The | symbol is used to indicate technical and major
editorial changes</para>
       </section></body></engineering.doc>

My Stylesheet, thus far looks something like this:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="2.0">
    <xsl:output doctype-system="EngineeringDoc.dtd" encoding="UTF-8"
indent="yes" method="xml"
        version="1.0"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="/">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="XML">
        <engineering.doc trans.canada.note="no" status="draft"
export.control="no" qmsp.additional.requirements="no">
            <dm>
                <dm.frontmatter><!--some elements--></dm.frontmatter>
                <body>
                    <xsl:for-each-group select="*"
group-starting-with="Heading-1">
                        <section>
                            <xsl:for-each select="current-group()">
                                <xsl:apply-templates select="."/>
                            </xsl:for-each>
                            <xsl:for-each-group select="*"
group-starting-with="Heading-2">
                                <section>
                                    <xsl:for-each select="current-group()">
                                        <xsl:apply-templates
select="."></xsl:apply-templates>
                                    </xsl:for-each>
                                    <xsl:for-each-group select="*"
group-starting-with="Heading-3">
                                        <section>
                                            <xsl:for-each
select="current-group()">
                                                <xsl:apply-templates
select="."></xsl:apply-templates>
                                            </xsl:for-each>
                                        </section>
                                    </xsl:for-each-group>
                                </section>
                            </xsl:for-each-group>
                        </section>
                    </xsl:for-each-group>
                </body>
            </dm>
        </engineering.doc>
    </xsl:template>
    <xsl:template match="Body | Normal">
        <para>
            <xsl:apply-templates/>
        </para>
    </xsl:template>
    <xsl:template match="Heading-1| Heading-2 | Heading-3 | Heading-4 |
Heading-5">
        <heading>
            <xsl:if test="A">
                <xsl:attribute name="id">
                    <xsl:value-of select="A[1]/@ID"/>
                </xsl:attribute>
            </xsl:if>
            <xsl:apply-templates />
        </heading>
    </xsl:template>
</xsl:stylesheet>

This is the result I get using Saxon 8B:
<?xml version="1.0" encoding="UTF-8"?>

<!DOCTYPE engineering.doc
  SYSTEM "EngineeringDoc.dtd">
<engineering.doc trans.canada.note="no" status="draft" export.control="no"
qmsp.additional.requirements="no">
   <dm>
      <dm.frontmatter><!--some elements--></dm.frontmatter>
      <body>
         <section/>
         <section>
            <heading id="pgfId-1009125"> CASINGS</heading>
            <para>  Designer's responsibility</para> <!--list stuff-->
          <heading id="pgfId-1012502"> Applicable Documents</heading>
            <para> The following publications form a part of this document
to the
        extent specified herein</para>
            <section/>
         </section>
         <section>
            <heading id="pgfId-1010000"> NOTE</heading>
            <para> The | symbol is used to indicate technical and major
editorial
        changes </para>
            <section/>
         </section>
      </body>
   </dm>
</engineering.doc>

Does anyone know how I can get the desired  result?

TIA

Nadia

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.