[xsl] Moving (promoting) XML elements through XSL

Subject: [xsl] Moving (promoting) XML elements through XSL
From: "Mark Peters" <flickrmeister@xxxxxxxxx>
Date: Thu, 29 Jun 2006 16:41:56 -0400
Hi folks,

I'm trying to apply XSL to my input XML document to accomplish two tasks:

1. Promote the indexterm elements in my XML doc to the same level as
my title and body elements.
2. Wrap the indexterm element in additional elements.


Input XML:


<topic id="i267011">
     <title>
        <indexterm>Hardware Requirements</indexterm>
        <indexterm>Software Requirements</indexterm>Software Requirements
     </title>
     <body>
   ..
     </body>
</topic>


Output XML:


<topic id="i267011">
     <title>Software Requirements
     </title>
     <prolog>
         <metadata>
             <keywords>
                <indexterm>Hardware Requirements</indexterm>
                <indexterm>Software Requirements</indexterm>
             </keywords>
          </metadata>
      </prolog>
     <body>
   ..
     </body>
</topic>


Based on XSL I've studied in the archive, the FAQ, and in other lists, I created the following stylesheet, which *should* at least promote the indexterm elements (I haven't figured gotten as far as wrapping the indexterm elements yet):

<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:copy-of select="/title/indexterm"/>
           <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
   </xsl:template>
   <xsl:template match="indexterm"/>
   <xsl:template match="@*|node()">
       <xsl:copy>
           <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
   </xsl:template>
   <!-- Copy any nodes not covered above. -->
   <xsl:template match="@*|node()">
       <xsl:copy>
           <xsl:apply-templates select="@*|node()"/>
       </xsl:copy>
   </xsl:template>
</xsl:stylesheet>


When I apply the stylesheet to my input XML doc, my indexterm elements disappear.

Current result:

<topic id="i267011">
     <title>Software Requirements
     </title>
     <body>
   ..
     </body>
</topic>


I'd be grateful for any assistance.


Thanks in advance!

Mark

--

Mark Peters
Senior Technical Writer
Saba Software

--

Mark Peters
Senior Technical Writer
Saba Software

Current Thread