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: Dynamic Table Generation


nigel.byrnes@philips.com 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

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