[Home] [By Thread] [By Date] [Recent Entries]

  • From: Bob DuCharme <bob@u...>
  • To: Thushara Perera <thusharap@e...>,"XSL News Group (E-mail)" <XSL-List@l...>,"XML-DEV (E-mail)" <xml-dev@l...>
  • Date: Thu, 31 May 2001 10:13:28 -0400

>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            http://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>

Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member