RE: [xsl] Create table with optional elements

Subject: RE: [xsl] Create table with optional elements
From: "Martin Rowlinson \(MarrowSoft\)" <marrow@xxxxxxxxxxxxxx>
Date: Tue, 27 May 2003 12:15:17 +0100
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"

then try something like...

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
 xmlns:wn2="namespace-wn2" xmlns:wn1="namespace-wn1"
<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"
generate-id() = generate-id(key('kDistinctCols',.))]"/>
<xsl:template match="wn2:ArrayOfToken_Response">
      <table border="1">
        <!-- header row -->
          <xsl:for-each select="$DistinctCols">
              <xsl:value-of select="."/>
        <!-- data rows -->
        <xsl:apply-templates select="wn1:Token"/>

<xsl:template match="wn1:Token">
  <xsl:variable name="this-terms" select="wn1:term/wn1:Term"/>
    <xsl:for-each select="$DistinctCols">
      <xsl:variable name="this-cell" select="$this-terms[wn1:lang =
          <xsl:when test="$this-cell">
            <xsl:value-of select="$this-cell/wn1:data"/>
            <!-- do whatever you want to indicate no cell content -->

Hope this helps
Marrow - home of Xselerator (XSLT IDE and debugger)

 XSL-List info and archive:

Current Thread