Re: [xsl] alphabetic counters

Subject: Re: [xsl] alphabetic counters
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 10 May 2004 14:42:17 -0400
Hi Nick,

At 02:12 PM 5/10/2004, you wrote:
But I still have some CDATA and escaping going on. This occurs when creating table rows:

<tr>...

<xsl:if test="position() != 1">
  <xsl:text disable-output-escaping="yes"><![CDATA[<tr class="]]></xsl:text>
  <xsl:copy-of select="$planetbg"/>
  <xsl:text disable-output-escaping="yes"><![CDATA[">]]></xsl:text>
</xsl:if>

...

<xsl:if test="position() != last()">
  <xsl:text disable-output-escaping="yes"><![CDATA[</tr>]]></xsl:text>
</xsl:if>

...</tr>

It's designed to create new rows like this:

<tr>
        <th rowspan="3">...</th>
        <td>some data</td>
</tr>
<tr>
        <td>more data</td>
</tr>
<tr>
        <td>row 3 of the header</td>
</td>

David C provides the answer to this in the first entry of the FAQ page on tables, at http://www.dpawson.co.uk/xsl/sect2/N7450.html. This amounts to a little grouping problem. For example, if you wanted each row to have three cells, you would select every third node of those you wanted to map to the table, and create its row, its cell and that of the two nodes that go with it. (And then make sure you don't process those other two nodes on their own.) So you're grouping your cells by threes into your rows, and your rows do not have to be "split" with a start-tag here and an end-tag over there.


In general, you're learning how XSLT works: it's a node-selection and manipulation language, not as "tag-writing" language. This is very consequential. Among other things, it means that stylesheets can all be well-formed XML documents (since it doesn't need to consider "tags" as "data"), which makes many aspects of authoring and debugging them much easier: an entire set of problems just never come up.

But outputting nodes within an xml:if and closing them within another causes parse errors in Libxslt and Sablotron.

And in any other XML parser, as it should.


<xsl:attribute name="href">
<xsl:value-of select="concat('#',@cite)" />
<xsl:number count="/catalogue/citation[@author=id(@cite)/@author and @year=id(@cite)/@year]" format="a"/>
</xsl:attribute>

<xsl:number> doesn't work for me. I tried putting it in a variable and outputting the variable as a test and nothing was produced.

The syntax of the count attribute up there looks questionalble to me, depending as it does on the id() function, etc. (The id() function only works when a DTD is available and has declared ID attributes.)


Others have suggested using keys, which would allow a more robust solution.

If it were me, however, I probably wouldn't ask this stylesheet to generate the "a", "b" etc.; I'd have managed that earlier in the pipeline (with or without XSLT) and the citations would already have their proper labels. :->

nor was anything output by David's
<xsl:number format="a" count="reference[@author=current()/@author][@year=current()/@year]"/>
or by changing " and " to "][" in Andreas' version.


The key approach from Michael Key didn't seem to work from just copying and pasting, but I will read the docs on keys and see if i can fix it.

Yah, do that. :->


Also, try adding level="any" to David's xsl:number and see if that helps.

I'm using Libxslt and Sablotron - Saxon and Xalan-J cannot parse the xsl file properly, so I am not bothering with them. I don't know what versions I have, whichever ones are bundled with Marc Liyanage's TestXSLT 3.0 software (http://www.entropy.ch/software/macosx/)

Saxon and Xalan-J are both industrial-grade, conformant processors, so if your code doesn't work with them, it's more likely to be a problem with the code, not the processor.


Good luck,
Wendell


====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================

Current Thread