OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Move a section in XSL



>I want to move the SUPPLIER section into the ARTICLE section and leave the rest as it is. Please tell me
>how to do this ?
 
(After seeing your posting on xml-dev and then opening with a comment about how xsl-list is a better place for XSL(T) stylesheet issues, I now see that you cc'd your posting to xsl-list. I don't see any answer there yet, so I'll forge ahead.)
 
One problem is that your XML couldn't be valid: the DOCTYPE declaration said that the document element was ARTICLE, but the SUPPLIER element came before the ARTICLE element. The document element has to enclose everything else.
 
To process it, you could do this: remove the DOCTYPE declaration and add some other element (I'll call it TEMP) around the whole thing to make it well-formed. The stylesheet below should then do what you need. I tried to comment it a lot.
 
Bob DuCharme            www.snee.com/bob             <bob@ 
snee.com>      see http://www.snee.com/bob/xsltquickly for
info on upcoming "XSLT Quickly" from Manning Publications.

 
<!-------- beginning of stylesheet ------------->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="1.0">
 
  <xsl:template match="TEMP">
     <!-- Assumes that TEMP's only children are SUPPLIER and ARTICLE.
          Process ARTICLE child but not SUPPLIER child. -->
     <xsl:apply-templates select="ARTICLE"/>
  </xsl:template>
 
  <xsl:template match="ARTICLE">
    <ARTICLE xml:lang="en">
      <!-- Put SUPPLIER sibling after ARTICLE start
           tag, then ARTICLE's other children.        -->
      <xsl:apply-templates select="../SUPPLIER"/>
      <xsl:apply-templates/>
    </ARTICLE>
  </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>