Subject: Re: Dynamic Table Generation From: Phil Lanch <phil@xxxxxxxxxxxxxxx> Date: Tue, 07 Mar 2000 12:58:18 +0000 |
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Dynamic Table Generation, nigel . byrnes | Thread | Re: Dynamic Table Generation, Steve Tinney |
Re: XSLT vs OmniMark, Louis-Dominique Dube | Date | Re: Dynamic Table Generation, Steve Tinney |
Month |