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

RE: Create table with optional elements

Subject: RE: Create table with optional elements
From: "Martin Rowlinson \(MarrowSoft\)" <marrow@xxxxxxxxxxxxxx>
Date: Tue, 27 May 2003 12:15:17 +0100
xslt create table with values
Hi Ricardo,

Assuming that you have your namespaces declared, e.g.

<wn2:ArrayOfToken_Response i:type="wn1:ArrayOfToken"
  xmlns:wn2="namespace-wn2" xmlns:wn1="namespace-wn1"
xmlns:i="namespace-i">
  ....

then try something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:wn2="namespace-wn2" xmlns:wn1="namespace-wn1"
xmlns:i="namespace-i">
<xsl:output method="html" indent="yes"/>
<!-- key for finding distinct columns -->
<xsl:key name="kDistinctCols" match="wn1:lang" use="."/>
<!-- find distinct columns here so that they can be re-used in different
templates -->
<xsl:variable name="DistinctCols"
select="/wn2:ArrayOfToken_Response/wn1:Token/wn1:term/wn1:Term/wn1:lang[
generate-id() = generate-id(key('kDistinctCols',.))]"/>
<xsl:template match="wn2:ArrayOfToken_Response">
  <html>
    <body>
      <table border="1">
        <!-- header row -->
        <tr>
          <xsl:for-each select="$DistinctCols">
            <xsl:sort/>
            <th>
              <xsl:value-of select="."/>
            </th>
          </xsl:for-each>
        </tr>
        <!-- data rows -->
        <xsl:apply-templates select="wn1:Token"/>
      </table>
    </body>
  </html>
</xsl:template>

<xsl:template match="wn1:Token">
  <xsl:variable name="this-terms" select="wn1:term/wn1:Term"/>
  <tr>
    <xsl:for-each select="$DistinctCols">
      <xsl:sort/>
      <xsl:variable name="this-cell" select="$this-terms[wn1:lang =
current()]"/>
      <td>
        <xsl:choose>
          <xsl:when test="$this-cell">
            <xsl:value-of select="$this-cell/wn1:data"/>
          </xsl:when>
          <xsl:otherwise>
            <!-- do whatever you want to indicate no cell content -->
            <xsl:text>[none!]</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </td>
    </xsl:for-each>
  </tr>
</xsl:template>
</xsl:stylesheet>


Hope this helps
Marrow
http://www.marrowsoft.com - home of Xselerator (XSLT IDE and debugger)
http://www.topxml.com/Xselerator




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


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.