Re: [xsl] too many columns

Subject: Re: [xsl] too many columns
From: Mike Brown <mike@xxxxxxxx>
Date: Thu, 24 Oct 2002 02:03:27 -0600 (MDT)
Jarno.Elovirta@xxxxxxxxx wrote:
> > I have a xml/xsl duet where i would like to render multiple 
> > tables with the
> > info that is between the <Page></Page> tags as seen in the 
> > XML (source) here
> >
> For future reference, it would probably be better if you posted a sample from your source that shows the problem, instead of pointing to a file on the net, so people won't have to wget it.

There's nothing wrong with posting a URL to the source. It's a not a large
file at all, but is larger than ought to be posted to the list.

One problem with the source, offhand, is that there are elements named
'XMLData' and 'XMLNodeName'. While this doesn't break well-formedness, it is
in violation of the XML 1.0 spec, because it starts with 'XML' yet isn't a
name standardized upon by the W3C. Choose a different name that does not start
with 'XML' (case-insensitive).

> > However, my column headers are rendered perfectly fine, but I 
> > have more columns that I need instead of having the first 
> > <Page></Page>table content
> > in the first table and the second <Page></Page> in the second table.
> > 
> > It is hard to explain but I guess seeing it will help you understand.
> > 
> > The stylesheet is here:
> >
> Anyhow, it seems that you're using the Microsoft-XSL-dialect-that-has-nothing-to-do-with-XSLT-1.0. Thus, you should either ask Microsoft for assistance or e.g. see Microsoft XSL FAQ <>, or rewrite you stylesheet in XSLT 1.0, and come back if you're having problems with that.

I wasn't going to attempt to reproduce the VBScript's functionality, but it
looks like most of it wasn't even needed. The following does not use any
pre-XSLT-1.0-specific constructs, and will probably produce output very close
to what was expected. It seems to work in IE, but I can't test with MSXML2
(IE5.0), myself.

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

  <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" mode="thead" />
        <tbody class="TableBody">
          <xsl:apply-templates select="People/Person" />

  <xsl:template match="Caption">
    <xsl:value-of select="." />

  <xsl:template match="Column" mode="thead">
    <th nowrap="yes" class="TableHeading">
      <xsl:apply-templates select="Caption" />

  <xsl:template match="Person">
      <xsl:apply-templates select="Data/*" />

  <xsl:template match="A1|A2|A3|A4|A5|A6">
    <td valign="top">
      <xsl:attribute name="style">color:#<xsl:choose>
          <xsl:when test="@color">
              <xsl:value-of select="@color" />
          <xsl:when test="@fond">
              <xsl:value-of select="@fond" />
      <xsl:value-of select="." />


If you change the namespace, it should work as XSLT 1.0.

Note that I did circumvent the logic for finding which 'A' element to process
(A1, A2, A3, etc.) by looking at the Column specifications. The example data
had them all in order. If they will not really be in order, and since MSXML2
does not permit the XPath functions that would be needed to sort them, you'll
have to ask in an MSXML specific forum.

Anyway, I hope this helps at least with sorting out the colors and number
of columns, and helps reduce the stylesheet to a more manageable size.
There was a lot of unnecessary stuff in it. In general, any time you do

<xsl:template match="foo">
  <xsl:for-each select="bar">

you probably could have changed the xsl:apply-templates to select
"foo/bar", and then made a template that matches bar instead of foo.

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

 XSL-List info and archive:

Current Thread