xsl-list
[Top] [All Lists]

RE: xsl grouping problem

2004-03-23 14:44:56
The following-sibling:: axis operates at the document level, not over the 
current node set. This means that when select the following-sibling from the ID 
node you get TYPE, REP, SYMBOL etc.

instead of using node() use the element that you want, for instance, of you 
want the next ID node then use select="following-sibling::ID[1]"

here is some code that does what you want...

Josh


  <xsl:template match="/">
    <xsl:for-each select="DATABASE/ID[position() mod 3 = 1]">
    <tr>
      <xsl:call-template name="ID">
        <xsl:with-param name="id" select="."/>
      </xsl:call-template>

      <xsl:call-template name="ID">
        <xsl:with-param name="id" select="following-sibling::ID[1]"/>
      </xsl:call-template>

      <xsl:call-template name="ID">
        <xsl:with-param name="id" select="following-sibling::ID[2]"/>
      </xsl:call-template>
    </tr>

    </xsl:for-each>
  </xsl:template>

  <xsl:template name="ID">
    <xsl:param name="id"/>
    <td>
    <xsl:choose>
      <xsl:when test="$id">
        <xsl:value-of select="$id"/> - <xsl:value-of 
select="$id/following-sibling::TYPE[1]"/> - <xsl:value-of 
select="$id/following-sibling::SYMBOL[1]"/>
      </xsl:when>
      <xsl:otherwise>&#160;</xsl:otherwise>
    </xsl:choose>
    </td>
  </xsl:template>


-----Original Message-----
From: rj_peterson(_at_)dstoutput(_dot_)com 
[mailto:rj_peterson(_at_)dstoutput(_dot_)com]
Sent: Tuesday, March 23, 2004 12:03 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] xsl grouping problem






I have the following xml file that I want to use to create a table with the
values in the format below.  I have some xsl I have been trying but I cant
get the following-sibling to quite work right.  Any suggestions??  Thanks!!

XML
<?xml version="1.0"?>
  <DATABASE>
     <ID>306030300570011572</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>OMCL</SYMBOL>
     <ID>306030300570011573</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>ORCL</SYMBOL>
     <ID>306030300570011571</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>TLCV</SYMBOL>
     <ID>306030300570011572</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>OMCL</SYMBOL>
     <ID>306030300570011573</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>ORCL</SYMBOL>
       .........
     <ID>306030300570011571</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>TLCV</SYMBOL>
     <ID>306030300570011572</ID>
     <TYPE>18</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>OMCL</SYMBOL>
     <ID>306030300570011573</ID>
     <TYPE>18</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>ORCL</SYMBOL>
     <ID>306030300570011571</ID>
     <TYPE>20</TYPE>
     <REP>CKCK</REP>
     <SYMBOL>TLCV</SYMBOL>
  </DATABASE>

XSL
<xsl:variable name="symbol" select="DATABASE/SYMBOL"/>
<xsl:variable name="type" select="DATABASE/TYPE"/>
<xsl:for-each select="DATABASE/ID[position() mod 3 = 1]">
  <xsl:variable name="position" select="position()"/>
  <tr>
     <td>
       <xsl:value-of select="."/>-<xsl:value-of select="$type"/>-
                         <xsl:value-of select="$symbol[$position]"/>
     </td>
     <xsl:for-each select="following-sibling::node()[position() &lt; 3]">
       <td>
          <xsl:value-of select="."/>-<xsl:value-of select="$type"/>-
            <xsl:value-of select="$symbol[$position]"/>
       </td>
     </xsl:for-each>
  </tr>
</xsl:for-each>


Desired html
<table>
     <tr>
       <td>IDVALUE - TYPEVALUE - SYMBOVALUEL</td>
       <td>IDVALUE - TYPEVALUE - SYMBOVALUEL</td>
       <td>IDVALUE - TYPVALUEE - SYMBOVALUEL</td>
     </tr>
     <tr>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
     </tr>
       ...................
     <tr>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
       <td>IDVALUE - TYPEVALUE - SYMBOLVALUE</td>
     </tr>
</table>


<Prev in Thread] Current Thread [Next in Thread>
  • RE: xsl grouping problem, Josh Canfield <=