[xsl] Dropping unwanted period a the end of <forename> node.

Subject: [xsl] Dropping unwanted period a the end of <forename> node.
From: Charles Muller <cmuller-lst@xxxxxxxxxxxxxxx>
Date: Wed, 23 May 2012 19:31:19 +0900
I've been keeping my bibliographies in TEI <biblStruct> format for many years, but I've been using the <author> node with plain text inside like this:

<author>Bauman, Syd</author>

rather than using the <forename> and <surname> tags.

Recently I began to use the more specific format of

<author><surname>Bauman</surname><forename>Syd</forename></author>

...but have run into an XSLT problem that has me stymied.

As everyone knows, in bibliography output we have to deal with the case where the forename might end in a period, and where the output adds a period after the author's name. I.e., we don't want

Muller, Albert C.

to end up as

Muller, Albert C..

To deal with this problem in my old system, I was using this kind of structure:

<xsl:template match="author">

[...]

  <xsl:when test="substring(., string-length(.)) = '.'">
  <xsl:apply-templates/>
  <xsl:text>&#160;</xsl:text>
  </xsl:when>
</xsl:choose>

In other words, in the case where the author name ends in a period, only inserting a space after, without a period.

I'm now trying to create the same kind of function in the case where the <forename> tag is used, to test whether or not the forename has a period, and outputting with or without a period accordingly. After spending half a day on this, the closest I could come up with was the following code, which does not do the trick. I present it here as a continuation of the above example:

<xsl:when test="substring(., string-length(.)) = '.'">
<xsl:apply-templates/>
<xsl:text>&#160;</xsl:text>
</xsl:when>
<xsl:otherwise>
  <xsl:choose>
    <xsl:when test="child::surname">
<xsl:choose>

{next, in the case of the presence of a period in the forename, we output without a period}

<xsl:when test="substring(forename, string-length(.)) = '.'">
<xsl:value-of select="surname" />, <xsl:value-of select="forename" /><xsl:text>&#160;</xsl:text>
</xsl:when>


{next, in the other case, where there is no period in the forename, we output with a period}

<xsl:otherwise>
<xsl:value-of select="surname" />, <xsl:value-of select="forename" /><xsl:text>.&#160;</xsl:text>
</xsl:otherwise>



I believe I must have an XPath error of some sort, but have not been able to identify it. Any help will be greatly appreciated. In case it is necessary, I include the full code below.


Regards,

Chuck

----------------------------------------

<xsl:template match="author">

<!-- 2003-08-01
If our author name is the same as the preceding one, output a string of dashes in its place. NB this presupposes that identical names are indeed entered identically! It might also be a wise precaution to normalize-space both the string values we are comparing. Also, the "suppression marker" perhaps ought to be in a variable rather than hard-coded as here.
-->


<xsl:choose>
<xsl:when test="preceding::biblStruct[1]/*/author = .">
<xsl:text>----.&#160;</xsl:text>
</xsl:when>
<xsl:when test="preceding::biblStruct[1]/*/editor = .">
<xsl:text>----.&#160;</xsl:text>
</xsl:when>
<xsl:when test="preceding::bibl[1]/author = .">
<xsl:text>----.&#160;</xsl:text>
</xsl:when>
<xsl:when test="preceding::bibl[1]/editor = .">
<xsl:text>----.&#160;</xsl:text>
</xsl:when>
<xsl:when test="preceding::bibl[1]/*/author = .">
<xsl:text>----.&#160;</xsl:text>
</xsl:when>
<xsl:when test="substring(., string-length(.)) = '.'">
<xsl:apply-templates/>
<xsl:text>&#160;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="child::surname">
<xsl:choose>
<xsl:when test="substring(forename, string-length(.)) = '.'">
<xsl:value-of select="surname" />, <xsl:value-of select="forename" /><xsl:text>&#160;</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="surname" />, <xsl:value-of select="forename" /><xsl:text>.&#160;</xsl:text>
</xsl:otherwise>
</xsl:choose></xsl:when>
<xsl:otherwise>
<xsl:apply-templates/><xsl:text>.&#160;</xsl:text>
</xsl:otherwise></xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>






-------------------

A. Charles Muller

University of Tokyo
Graduate School of Humanities and Sociology, Faculty of Letters
Center for Evolving Humanities
7-3-1 HongE
, BunkyE
-ku
Tokyo 113-8654, Japan

Office: 03-5841-3735

Web Site: Resources for East Asian Language and Thought
http://www.acmuller.net

<acmuller[at]jj.em-net.ne.jp>

Mobile Phone: 090-9310-1787

Twitter @acmuller4

Current Thread