Re: [xsl] too many columns

Subject: Re: [xsl] too many columns
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 24 Oct 2002 13:00:00 -0600 (MDT)
Gabi Bucataru wrote:
> 1.
> See,  the thing is that i will never know how many of those A1, A2 elements
> (and so on)  I will have. Once it might be only 2, 4, who knows. So is there
> a way that I can make the template dynamic? I mean this one (now I have 6
> A's there):
> <xsl:template match="A1|A2|A3|A4|A5|A6">

But you handle each of these elements the same way, so this template does not
really need to change. What needs to change is how you arrive at this 
template: the selection of nodes for processing (xsl:apply-templates or

Also, in the stylesheet I posted for you, I didn't mean to use mode="thead"..
that was leftover from an experiment.

> 2.
> The second question is that I would like to start look into XSLT 1.0... Can
> you please point me to a resource to learn that? I would like to make this
> move.

1. The book "Beginning XSLT" by Jeni Tennison
2. The book "XSLT Reference" by Michael Kay
3. These free excerpts from other books:
4. (decent tutorial)
5. (learn by example)

You are lucky I didn't delete the XSLT 1.0 version of your stylesheet that I
had dumbed down to make work with the WD-xsl namespace.

I cannot imagine making this new one work with the WD-xsl namespace, though,
because it makes use of XSLT 1.0 instructions like xsl:variable and functions
like current(), local-name(), and string(). No one who uses XSLT would want to
have to live without them!

   - Mike
  mike j. brown                   |  xml/xslt:
  denver/boulder, colorado, usa   |  resume:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"

  <xsl:output method="html" indent="yes" />

  <xsl:template match="/">
        <style type="text/css"> {page-break-after: always}
     body {background-color:#cccccc; margin:0
    .TableBody {background: white;
       font-family: arial; 
       font-size: 9px}
    .TableHeading  {border-top-width:1;
        <!-- rest of head here -->
        <xsl:apply-templates select="XMLData/Page" />

  <xsl:template match="Page">
    <p class="page">
      <table style="background: black" cellspacing="1" width="600">
          <xsl:apply-templates select="Columns/Column" />
        <tbody class="TableBody">
          <xsl:apply-templates select="People/Person" />

  <xsl:template match="Column">
    <th nowrap="yes" class="TableHeading">
        <xsl:when test="string(Caption)">
          <xsl:value-of select="Caption" />

  <xsl:template match="Person">
      <xsl:variable name="thisPerson" select="." />
      <xsl:for-each select="../../Columns/Column">
        <xsl:variable name="thisColumnData" select="$thisPerson/Data/*[local-name()=current()/XMLNodeName]" />
          <xsl:when test="$thisColumnData">
            <xsl:apply-templates select="$thisColumnData" />
            <td valign="top" style="color:#000000;background-color:#FFFFFF">&#160;</td>

  <xsl:template match="A1|A2|A3|A4|A5|A6">
    <xsl:variable name="color">
      <xsl:if test="@color">
        <xsl:value-of select="@color"/>
    <xsl:variable name="bgcolor">
      <xsl:if test="@fond">
        <xsl:value-of select="@fond"/>
    <td valign="top">
      <xsl:attribute name="style">
          <xsl:when test="$color != ''">
              <xsl:value-of select="$color"/>
          <xsl:when test="$bgcolor != ''">
              <xsl:value-of select="$bgcolor"/>
        <xsl:when test="string(.)">
          <xsl:value-of select="." />


 XSL-List info and archive:

Current Thread