Print

Print


Hi,

Ethan's recommendation will work, but a more aggressive refactoring
may also be a good idea:

<xsl:template match="eadheader">
  <xsl:apply-templates mode="header" select="filedesc/titlestmt/titleproper"/>
  <xsl:apply-templates mode="header" select="filedesc/titlestmt/sponsor"/>
  <br></br>
</xsl:template>

<xsl:template mode="header" match="titleproper">
    <h2 style="text-align:center">
        <a name="{generate-id(.)}">
            <xsl:apply-templates/>
        </a>
    </h2>
</xsl:template>

<xsl:template mode="header" match="sponsor">
    <h5 style="text-align:center">
        <a name="{generate-id(.)}">
            <xsl:apply-templates/>
        </a>
    </h5>
</xsl:template>

Advantages to this approach:

* Won't break if you have more than one titleproper or sponsor
* Won't erase any inline markup appearing inside either element,
instead permitting it to be processed
* Easier to read, modify and debug

One might also tighten the HTML, so:

<xsl:template match="eadheader">
  <div style="text-align:center; margin-bottom: 2em">
    <xsl:apply-templates mode="header" select="filedesc/titlestmt/titleproper"/>
    <xsl:apply-templates mode="header" select="filedesc/titlestmt/sponsor"/>
 </div>
</xsl:template>

<xsl:template mode="header" match="titleproper">
    <h2 id="{generate-id(.)}">
        <xsl:apply-templates/>
    </h2>
</xsl:template>

<xsl:template mode="header" match="sponsor">
    <h5 id="{generate-id(.)}">
        <xsl:apply-templates/>
    </h5>
</xsl:template>

Cheers, Wendell
Wendell Piez | http://www.wendellpiez.com
XML | XSLT | electronic publishing
Eat Your Vegetables
_____oo_________o_o___ooooo____ooooooo_^


On Tue, Jan 21, 2014 at 1:47 PM, Ethan Gruber <[log in to unmask]> wrote:
> Put a test around the h5 so it only appears when there is content in
> sponsor:
>
> <xsl:if test="string(filedesc/titlestmt/sponsor)">
> <h5 style="text-align:center">
>             <xsl:value-of select="filedesc/titlestmt/sponsor"/>
> </h5>
> </xsl:if>
>
>
>
> On Tue, Jan 21, 2014 at 1:43 PM, Tamara Gaydos <[log in to unmask]>
> wrote:
>>
>> Hi all,
>>
>> I have a stylesheet that works fine when the <sponsor> element is filled
>> in. But now I want to encode some finding aids that have no sponsor. If I
>> try to eliminate the <sponsor> element, the header information becomes
>> centered and looks awful. The only bit of code that references <sponsor> is
>> this:
>>
>> <!--Suppreses all other elements of eadheader.-->
>>     <xsl:template match="eadheader">
>>     <h2 style="text-align:center">
>>         <a name="{generate-id(titlestmt/titleproper)}">
>>             <xsl:value-of select="filedesc/titlestmt/titleproper"/>
>>         </a>
>>     </h2>
>>     <h5 style="text-align:center">
>>             <xsl:value-of select="filedesc/titlestmt/sponsor"/>
>>     </h5>
>>     <br></br>
>>     </xsl:template>
>>
>> I want to be able to use sponsor when I need it and eliminate it when I
>> don't. Anyone able to help?
>>
>> Tamara Gaydos, CA
>> NHPRC Grant Project Manager and Manuscript Processor
>> Phillips Library | Peabody Essex Museum
>> East India Square | Salem, MA 01970
>> 978-542-1510 [log in to unmask]
>
>