tags:

views:

79

answers:

1

My XML Code

 <DBE:Attribute name="Test1" type="Table">
      <DBE:Table>
         <DBE:TableHeader>
            <DBE:TableColumn>t1</DBE:TableColumn>
            <DBE:TableColumn>t2</DBE:TableColumn>
            <DBE:TableColumn>t3</DBE:TableColumn>
            <DBE:TableColumn>t4</DBE:TableColumn>
            <DBE:TableColumn>t5</DBE:TableColumn>
            <DBE:TableColumn>t6</DBE:TableColumn>
            <DBE:TableColumn>t7</DBE:TableColumn>
            <DBE:TableColumn>t8</DBE:TableColumn>
            <DBE:TableColumn>t9</DBE:TableColumn>
            <DBE:TableColumn>t10</DBE:TableColumn>
            <DBE:TableColumn>t11</DBE:TableColumn>
            <DBE:TableColumn>t12</DBE:TableColumn>
            <DBE:TableColumn>t13</DBE:TableColumn>
         </DBE:TableHeader>
         <DBE:TableRow>
            <DBE:TableData>0300 </DBE:TableData>
            <DBE:TableData/>
            <DBE:TableData>25</DBE:TableData>
            <DBE:TableData>25</DBE:TableData>
            <DBE:TableData>2009/09/03</DBE:TableData>
            <DBE:TableData/>
            <DBE:TableData>BAG</DBE:TableData>
            <DBE:TableData>rrr</DBE:TableData>
            <DBE:TableData>Yes</DBE:TableData>
            <DBE:TableData>12</DBE:TableData>
            <DBE:TableData>2009/03/09</DBE:TableData>
            <DBE:TableData>GO</DBE:TableData>
            <DBE:TableData/>
         </DBE:TableRow>
      </DBE:Table>
   </DBE:Attribute>

I would like my output to be ->

t7             t5                    t1               t13 --> Header
---------------------------------------------------------------
BAG        2009/09/03      0300            GO  --> ROW1
.............................................................. --> ROW2

and so on

My XSL code --> (for only selected values to be displayed)

           <xsl:for-each select="DBE:Attribute[@name='Test1']/DBE:Table/DBE:TableRow">
       <tr bgcolor="white">
              <xsl:for-each select="DBE:TableData">
          <td>
 <xsl:value-of select="node()|*">

      </xsl:value-of> 
   </td>
       </xsl:for-each>
       </tr>
    </xsl:for-each>
A: 

You could create a selector variable that holds the numeric position of columns you want. See the variable named "selector" below. Once you have that, a simple if in your TableData and TableColumn templates does the rest.

<?xml version="1.0" encoding="utf-8"?>
 <xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:DBE="foo.bar">

<xsl:variable name="selector">;1;5;7;12;</xsl:variable>

<xsl:template match="/">
    <xsl:apply-templates/>
</xsl:template>

<xsl:template match="DBE:Attribute">
    <html>
     <body><xsl:apply-templates/></body>
    </html>
</xsl:template>

<xsl:template match="DBE:Table">
    <table border="1">
     <xsl:apply-templates/>
    </table>
</xsl:template>

<xsl:template match="DBE:TableHeader">
  <tr>
    <xsl:apply-templates select="DBE:TableColumn"/>
    </tr>
</xsl:template>

<xsl:template match="DBE:TableColumn">  
  <xsl:variable name="pos">
    <xsl:text>;</xsl:text><xsl:value-of select="string(position())"/><xsl:text>;</xsl:text>
  </xsl:variable>

  <xsl:if test="contains($selector, $pos)">
  <th>
    <xsl:value-of select="."/>
  </th>
  </xsl:if>
</xsl:template>

<xsl:template match="DBE:TableRow">
  <tr>
    <xsl:apply-templates select="DBE:TableData"/>
  </tr>
</xsl:template>

<xsl:template match="DBE:TableData">
  <xsl:variable name="pos">
    <xsl:text>;</xsl:text><xsl:value-of select="string(position())"/><xsl:text>;</xsl:text>
  </xsl:variable>

  <xsl:if test="contains($selector, $pos)">
    <td>
      <xsl:value-of select="."/>
    </td>
  </xsl:if>
</xsl:template>

</xsl:stylesheet>
Andrew Cowenhoven