xsl-list
[Top] [All Lists]

RE: alphabetic counters

2004-05-10 09:30:00
-----Original Message-----
From: Nicholas Shanks [mailto:contact(_at_)nickshanks(_dot_)com]


What my problem is, is that references like the above are supposed to
be suffixed by a lower case alphabetic character ('a', 'b', etc.) after
the year if there are multiple 'citation' elements with identical
values for 'author' and 'year'. I have no idea how to go about doing
this. Can anyone suggest how to do this?


Hi,

I think you can use xsl:number to achieve this (?)

Also, this XSLT fragment:

<xsl:for-each select="reference">
   <xsl:text disable-output-escaping="yes"><![CDATA[<a
href="#]]></xsl:text><xsl:value-of select="@cite"/><xsl:text
disable-output-escaping="yes"><![CDATA[">]]></xsl:text>
   <xsl:value-of select="id(@cite)/@author" />
   <xsl:if test="id(@cite)/@year != ''"><xsl:text>
</xsl:text><xsl:value-of select="id(@cite)/@year" /></xsl:if>
   <xsl:text disable-output-escaping="yes"><![CDATA[</a>]]></xsl:text>
   <xsl:if test="position() != last()"><xsl:text>, </xsl:text></xsl:if>
</xsl:for-each>

Is the same as:

<xsl:for-each select="reference">
  <a href="{concat('#',@cite)}">
    <xsl:value-of select="id(@cite)/@author" />
    <xsl:if test="id(@cite)/@year != ''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="id(@cite)/@year" />
    </xsl:if>
  </a>
  <xsl:if test="position() != last()">
    <xsl:text>, </xsl:text>
  </xsl:if>
</xsl:for-each>

Remember: with XSLT you're outputting nodes rather than tags --IOW default
output is XML, while text output needs to be explicitly set.
So, generally speaking, you won't need to use <![CDATA[...]]> unless it is
*absolutely* necessary. A combination of CDATA and disable-output-escaping
is hinting that they're both superfluous (i.e. they serve no purpose in this
case but to make your code less readable --Hey, some developers like it that
way, as a form of long-term job-protection ;-)
Another purpose they serve is to trick the XSL processor into thinking that
it is *not* outputting XML while it actually is...

Starting from the above, a possible solution would look like:

<xsl:for-each select="reference">
  <a>
    <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:value-of select="id(@cite)/@author" />
    <xsl:if test="id(@cite)/@year != ''">
      <xsl:text> </xsl:text>
      <xsl:value-of select="id(@cite)/@year" />
    </xsl:if>
  </a>
  <xsl:if test="position() != last()">
    <xsl:text>, </xsl:text>
  </xsl:if>
</xsl:for-each>

HTH!

Greetz,

Andreas



<Prev in Thread] Current Thread [Next in Thread>