[xsl] applying templates to all but ...

Subject: [xsl] applying templates to all but ...
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Fri, 24 Sep 2004 05:25:37 -0400
My stylesheets have grown rather complicated, but let me try to narrow
down the problem I'm having to this:

I (think I) need to apply-templates to all elements in a namespace
except for one: cs:creator.  So I've tried this (and a ton of other
options on the relevant templates:

	    <xsl:apply-templates
select="$style-biblio/cs:reftype[@name='book']/cs:*[not(cs:creator)]">
	      <xsl:with-param name="source" select="."/>
	    </xsl:apply-templates>

.... but am ending up with output like this (note extra "H. Arendt"):

           <p class="bibref" id="two"><span class="creator">Arendt, H.
</span><span class="title italic ">The Human Condition</span>, H.
Arendt(<span class="year">1959</span>)<span class="origin"><span
class="place">New York</span>:<span
class="publisher">Doubleday</span></span>.</p>

To try to sum up in a nutshell:

I had a rather complex set of stylesheets that I am now making more
complex by integrating processing based on a config file (in the cs
namespace) that drives formatting of source data (in the mods
namespace).

The problem is that I'm getting duplicate names processed because my
main template does some funky grouping stuff with the creator names,
and I don't understand how to not have the mods:mods/mods:name
processed a second time, but insure that
mods:mods/mods:relatedItem/mods:name does get processed.

I'll paste the main templates in the hope that it makes sense to
someone!

<xsl:key name="bibref" match="mods:mods" use="@ID" />

<!-- take processed biblist and run templates on them in bib mode -->
<xsl:template
match="mods:modsCollection[$citation-class='author-year']"
mode="bibliography">
  <xsl:variable name="first" as="xs:boolean" select="position() = 1" />
  <xsl:variable name="author-name" select="bib:grouping-key(.)"/>
  <xsl:for-each-group select="mods:mods" group-by="bib:grouping-key(.)">
    <xsl:for-each select="current-group()">
      <xsl:variable name="first" as="xs:boolean" select="position() =
1" />
      <p class="bibref" id="{@ID}">
	<xsl:value-of select="$bibref-before"/>
	<span class="creator">
	  <xsl:choose>
	    <xsl:when test="count(current-group()) = 1">
	      <xsl:choose>
		<xsl:when test="not($first and position() = 1)">
		  <xsl:text>.</xsl:text>
		</xsl:when>
		<xsl:otherwise>
		  <xsl:choose>
		    <xsl:when test="mods:name">
		      <xsl:apply-templates select="mods:name" mode="full">
			<xsl:with-param name="sort-order"
				select="$style-biblio/@author-as-sort-order" />
		      </xsl:apply-templates>
		    </xsl:when>
		    <xsl:otherwise>
		      <xsl:value-of select="mods:noname-substitute"/>
		    </xsl:otherwise>
		  </xsl:choose>
		</xsl:otherwise>
	      </xsl:choose>
	    </xsl:when>
	    <xsl:otherwise>
	      <xsl:choose>
		<xsl:when test="mods:name">
		  <xsl:apply-templates select="mods:name" mode="full"/>
		</xsl:when>
		<xsl:otherwise>
		  <xsl:value-of select="mods:noname-substitute"/>
		</xsl:otherwise>
	      </xsl:choose>
	    </xsl:otherwise>
	  </xsl:choose>
	</span>
	<xsl:choose>
	  <xsl:when test="mods:relatedItem/@type = 'host'">
	    <xsl:variable name="issuance"
			  select="mods:relatedItem/mods:originInfo/mods:issuance" />
	    <xsl:choose>
	      <xsl:when test="$issuance = 'continuing'">
		<xsl:apply-templates
select="$style-biblio/cs:reftype[@name='article']/cs:*">
		  <xsl:with-param name="source" select="."/>
		</xsl:apply-templates>
	      </xsl:when>
	      <xsl:otherwise>
		<xsl:apply-templates
select="$style-biblio/cs:reftype[@name='chapter']/cs:*">
		  <xsl:with-param name="source" select="."/>
		</xsl:apply-templates>
	      </xsl:otherwise>
	    </xsl:choose>
	  </xsl:when>
	  <xsl:otherwise>
	    <xsl:apply-templates
select="$style-biblio/cs:reftype[@name='book']/cs:*">
	      <xsl:with-param name="source" select="."/>
	    </xsl:apply-templates>
	  </xsl:otherwise>
	</xsl:choose>
	<xsl:value-of select="$bibref-after"/>
      </p>
    </xsl:for-each>
  </xsl:for-each-group>
</xsl:template>

cs: creator looks like:

<xsl:template match="cs:creator">
  <xsl:param name="source"/>
  <xsl:apply-templates>
    <xsl:with-param name="source" select="$source"/>
  </xsl:apply-templates>
</xsl:template>

.... and mods:name (in full mode):

<xsl:template match="mods:name" mode="full">
<!-- We have two modes for name processing. "Full" renders complete
personal
names in bibliographies and footnote/endnote style ctiations, while
"short" renders just family name(s) commom in author-year citations. -->
  <xsl:param name="sort-order" select="first-author" />
  <xsl:param name="prefix"/>
  <xsl:param name="suffix"/>
  <xsl:value-of select="$prefix"/>
  <xsl:choose>
    <xsl:when test="$sort-order='first-author' and position() = 1 and
not(parent::mods:relatedItem)">
      <xsl:apply-templates select="mods:namePart[@type='family'] |
mods:namePart[not(@type)]"/>
      <xsl:text>, </xsl:text>
      <xsl:apply-templates select="mods:namePart[@type='given']"/>
    </xsl:when>
    <xsl:otherwise>
      <xsl:apply-templates select="mods:namePart[@type='given']"/>
      <xsl:apply-templates select="mods:namePart[@type='family'] |
mods:namePart[not(@type)]"/>
    </xsl:otherwise>
  </xsl:choose>
  <xsl:choose>
    <xsl:when test="position() = last()" />
    <xsl:when test="position() = last() - 1"> and </xsl:when>
    <xsl:otherwise>, </xsl:otherwise>
  </xsl:choose>
  <xsl:value-of select="$suffix"/>
</xsl:template>

The source data that is the problem looks like this:

<mods>
  <name>
    ...
  </name>
  <relatedItem>
    <name>
      ...
    </name>
  </relatedItem>
</mods>

Bruce

Current Thread