Re: [xsl] Sibling access in XSL !

Subject: Re: [xsl] Sibling access in XSL !
From: JBryant@xxxxxxxxx
Date: Thu, 23 Sep 2004 18:02:04 -0500
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