This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Dealing with WDDX-based data


(see below for solution)

Toni Geoly wrote:
> 
> I was wondering how many people were dealing with data sets
> that are generated using the WDDX protocol/DTD from
> ColdFusion.
> 
...
> 
> Are people working directly with this data, or instead
> using xsl:copy/xsl:copy-of to build new trees that are a
> bit more user-friendly?  

Yes, the column-first representation of the data is somewhat
counter-intuitive, and normally unhelpful.

However it's not a big deal. Here's a solution - someone may come up
with a cleaner, pure-recursion one, but this works.

D:\xmlSchema>type t.xml
<?xml version="1.0"?>
<root>
  <field name="field1">
    <string>field1.row1</string>
    <string>field1.row2</string>
    <string>field1.row3</string>
    <string>field1.row4</string>
  </field>
  <field name="field2">
    <string>field2.row1</string>
    <string>field2.row2</string>
    <string>field2.row3</string>
    <string>field2.row4</string>
  </field>
  <field name="field3">
    <string>field3.row1</string>
    <string>field3.row2</string>
    <string>field3.row3</string>
    <string>field3.row4</string>
  </field>
</root>


D:\xmlSchema>type t.xsl
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<!-- main body and loop -->
<xsl:template match="/">
  <html>
    <head>
      <title>Results</title>
    </head>
    <body>
      <table>
        <!-- get horizontal - <xsl:for-each> is inside the <tr> -->
        <tr>
          <xsl:for-each select="//field">
            <th>
              <xsl:apply-templates select="@name"/>
            </th>
          </xsl:for-each>
        </tr>
        <!-- get vertical - <tr>s are inside the <xsl:for-each>  -->
        <xsl:for-each select="//field[1]/string">
          <tr>
            <xsl:call-template name="row">
              <xsl:with-param name="row-no" select="position()"/>
            </xsl:call-template>
          </tr>
        </xsl:for-each>
      </table>
    </body>
  </html>
</xsl:template>

<!-- do a row here - use parameter to get position() into pattern -->
<xsl:template name="row">
  <xsl:param name="row-no"/>

  <xsl:for-each select="//field/string[position() = $row-no]">
    <td>
      <xsl:apply-templates/>
    </td>
  </xsl:for-each>
</xsl:template>
  
</xsl:stylesheet>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]