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

Re: Dynamic Table Generation

Subject: Re: Dynamic Table Generation
From: Phil Lanch <phil@xxxxxxxxxxxxxxx>
Date: Tue, 07 Mar 2000 12:58:18 +0000
xsl dynamic table generation
nigel.byrnes@xxxxxxxxxxx wrote:
> 
> context:
> I have a XML document that describes information about services including the content-types each that each service may utilise.
> 
> problem:
> I have to produce a table that captures the content-type that each service uses. With service-name on the y-axis of the table, the tricky part (to me) is that each content-type is to have it's own column (with content-type name as the column header on
> the x-axis). Then I have to put a cross in the appropriate table cell indicating that the content-type(s) a service may use.
> 
> candidate solution 1:
> One way I thought of doing it was to make to a pass over the XML document to generate a list of content-types. On the second pass over the document I can then build the table. Trouble is XSLT doesn't provide an equivalent to Java's Vector container
> object to store the content-types....

you can use a (top-level) variable to store some vector-ish XML -

<xsl:variable name="content-types">
  <!-- list of (unique) content-types: -->
  <xsl:for-each select="//content-type[not(.=following::content-type)]">
    <th><xsl:value-of select="."/></th>
  </xsl:for-each>
</xsl:variable>

- and then
(1) copy it into the output doc as the header of the table -

<xsl:copy-of select="$content-types"/>

(2) use it when producing each table row.  however, this involves using a
node-set() function to convert the variable from a "result tree fragment" (for
that is what it is) to a nodeset, & that's not a core XSLT function; there are
extension functions to do it in XT & Saxon & probably more ... -

<xsl:template match="service">
  <tr>
    <td><xsl:value-of select="@name"/></td>
    <xsl:variable name="s" select="."/>
    <xsl:for-each select="xt:node-set($content-types)/th">
      <td>
        <xsl:if test=".=$s/content-type">X</xsl:if>
      </td>
    </xsl:for-each>
  </tr>
</xsl:template>

-- 

cheers

phil

"How did you enjoy yourself with these people?
Answer: very much, almost as much as I do when alone."


 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.