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

Re: Sibling access in XSL !

Subject: Re: Sibling access in XSL !
From: JBryant@xxxxxxxxx
Date: Thu, 23 Sep 2004 18:02:04 -0500
xsl sibling text
Pardon me while I correct myself. It was recursing just fine. The three 
apply-templates statements were forcing the XSL processor to not process 
the XML in document order, which you wanted in this case. I apologize for 
any confusion.

If I may make a suggestion, I would change your XML structure to something 
like this:

<?xml version="1.0" encoding="UTF-8" standalone ="yes"?>
<FRUITS>
  <FRUIT>
    <IDENTIFICATION>
      <NAME>APPLE</NAME>
    </IDENTIFICATION>
    <APPEARANCE>
      <COLOR>RED</COLOR>
    </APPEARANCE>
    <STORAGE>
      <TEMP>STORE APPLES UNDER 20 DEGREE</TEMP>
    </STORAGE>
  </FRUIT>
  <FRUIT>
    <IDENTIFICATION>
      <NAME>GRAPE</NAME>
    </IDENTIFICATION>
    <APPEARANCE>
      <COLOR>BLACK</COLOR>
    </APPEARANCE>
    <STORAGE>
      <TEMP>STORE GRAPES UNDER 30 DEGREE</TEMP>
    </STORAGE>
  </FRUIT>
</FRUITS>

That way, you don't have to care about the document order.

The corresponding stylesheet would look like this:

<?xml version="1.0" encoding="UTF-8" standalone ="yes"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0">
  <xsl:template match="/">
    <HTML>
      <HEAD><TITLE>XSL TEST</TITLE></HEAD>
      <BODY>
        <TABLE>
          <xsl:apply-templates/>
        </TABLE>
      </BODY>
     </HTML>
  </xsl:template>
  <xsl:template match="FRUIT">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="IDENTIFICATION">
    <TR><TD><xsl:value-of select="NAME"/></TD></TR>
  </xsl:template>

  <xsl:template match="APPEARANCE">
    <TR><TD><xsl:value-of select="COLOR"/></TD></TR>
  </xsl:template>

  <xsl:template match="STORAGE">
    <TR><TD><xsl:value-of select="TEMP"/></TD></TR>
  </xsl:template>
</xsl:stylesheet>

I tested these files in Xalan and got the following HTML output (blank 
lines removed for the sake of brevity):

<HTML>
  <HEAD>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <TITLE>XSL TEST</TITLE>
  </HEAD>
  <BODY>
    <TABLE>
      <TR>
        <TD>APPLE</TD>
      </TR>
      <TR>
        <TD>RED</TD>
      </TR>
      <TR>
        <TD>STORE APPLES UNDER 20 DEGREE</TD>
      </TR>
      <TR>
        <TD>GRAPE</TD>
      </TR>
      <TR>
        <TD>BLACK</TD>
      </TR>
      <TR>
        <TD>STORE GRAPES UNDER 30 DEGREE</TD>
      </TR>
    </TABLE>
  </BODY>
</HTML>

Jay Bryant
Bryant Communication Services

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.