Re: [xsl] variable question

Subject: Re: [xsl] variable question
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Sun, 29 Aug 2004 11:08:25 -0400
On Aug 29, 2004, at 10:33 AM, Michael Kay wrote:

The most likely cause is that at the point you declare the variable reftype,
the context node does not have a mods:related item child.

Yes, that's become clear, since I have the same problem even when not using a variable. If I add // to the xpath expressions, I get a change (the "chapter" choice for the title-before variable renders), but it just renders on all titles (not what I want).


As Jeni says, perhaps this is a bad idea to have the global variable I want to apply in different contexts, but the advantage is obvious enough (if it can work at all!).

But you haven't given any information about the context.

The variable gets called like so:


<xsl:template match="mods:titleInfo[not(@type='abbreviated')]" mode="bibliography">
<xsl:choose>
<xsl:when test="../mods:relatedItem[@type='host']">
<span class="title">
<xsl:value-of select="$title-before"/>
<xsl:apply-templates select="mods:title"/>
<xsl:apply-templates select="mods:subTitle"/>
<xsl:value-of select="$title-after"/>
</span>
</xsl:when>
<xsl:otherwise>
<span class="title italic">
<xsl:value-of select="$title-before"/>
<xsl:apply-templates select="mods:title"/>
<xsl:apply-templates select="mods:subTitle"/>
<xsl:value-of select="$title-after"/>
</span>
</xsl:otherwise>
</xsl:choose>
</xsl:template>


This titleInfo element can occur either like so:

<mods:mods>
  <mods:titleInfo>

.... or like so:

<mods:mods>
  <mods:relatedItem>
    <mods:titleInfo>

The (global) variables again:

<xsl:variable name="reftype">
<xsl:choose>
<xsl:when test="not[mods:relatedItem[@type='host']]">
<xsl:text>book</xsl:text>
</xsl:when>
<xsl:when test="mods:relatedItem[@type='host']/mods:originInfo/mods: issuance='continuing'">
<xsl:text>article</xsl:text>
</xsl:when>
<xsl:when test="mods:relatedItem[@type='host']/mods:originInfo/mods: issuance='monographic'">
<xsl:text>chapter</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:variable>


<xsl:variable name="title-before">
   <xsl:choose>
     <xsl:when test="$reftype='chapter'">
       <xsl:text>"</xsl:text>
     </xsl:when>
     <xsl:otherwise>
       <xsl:text></xsl:text>
     </xsl:otherwise>
   </xsl:choose>
</xsl:variable>

Current Thread