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

Re: Moving (promoting) XML elements through XSL

Subject: Re: Moving (promoting) XML elements through XSL
From: "Mark Peters" <flickrmeister@xxxxxxxxx>
Date: Fri, 30 Jun 2006 09:33:39 -0400
outputting xml through xsl
BTW, this is never needed in a pattern. Just write "topic".

Good to know.


I celebrated too soon. When I apply the stylesheet against my input
file, I get the title, prolog, and body elements on the same level --
which is the desired result -- but title appears below prolog, which
is invalid against the DTD I'm working with. How could I output the
title element above the prolog element?


Input file:


<?xml version="1.0"?>
<topic>
    <title>
       <indexterm>Software Requirements</indexterm>Software Requirements
    </title>
    <body>
       <p>Some sample text</p>
    </body>
</topic>


Current output XML:


<?xml version="1.0"?>
<topic>
     <prolog>
           <metadata>
              <keywords>
                 <indexterm>
                    <indexterm>Software Requirements</indexterm>
                 </indexterm>
              </keywords>
           </metadata>
    </prolog>
    <title>
       <indexterm>Software Requirements</indexterm>Software Requirements
    </title>
    <body>
       <p>Some sample text</p>
    </body>
</topic>


Desired output XML:


<?xml version="1.0"?>
<topic>
    <title>
       <indexterm>Software Requirements</indexterm>Software Requirements
    </title>
     <prolog>
           <metadata>
              <keywords>
                 <indexterm>
                    <indexterm>Software Requirements</indexterm>
                 </indexterm>
              </keywords>
           </metadata>
     </prolog>
    <body>
       <p>Some sample text</p>
    </body>
</topic>


XSL:


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
     <xsl:output indent="yes"/>
     <xsl:template match="topic">
             <xsl:copy>
                     <xsl:apply-templates select="@*"/>
                     <prolog>
                             <metadata>
                                     <keywords>

<indexterm>

                                             <xsl:copy-of
select="title/indexterm"/>
                                              </indexterm>
                                     </keywords>
                             </metadata>
                     </prolog>
                     <xsl:apply-templates select="node()"/>
             </xsl:copy>
     </xsl:template>

<xsl:template match="indexterm[parent::title]"/>

     <xsl:template match="@*|node()">
             <xsl:copy>
                     <xsl:apply-templates select="@*|node()"/>
             </xsl:copy>
     </xsl:template>
</xsl:stylesheet>


Thanks, Mark

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.