Re: [xsl] Check if text is before an tag or not

Subject: Re: [xsl] Check if text is before an tag or not
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Nov 2003 13:41:29 +0000
Hi Sebastien,

> XML:
>
> <itemInv n="4">
>    <itemDesc>
>      <locus target="0101_II2618FOL0013V">fol. 13v</locus> 
>      <title TEIform="title">
>      <name reg="Séneca" type="person" role="author">Séneca</name> 
>      y 
>      <name reg="Cicerón, Marco Tulio" type="person" role="author">Cicerón</name> 
>       en castellano de los oficios 
>       </title>
>     </itemDesc>
> </itemInv>
[snip]
> The output should be:
> Séneca y Cicerón - de los oficios

It's not clear how this output is derivable from the XML that you've
given above. How do you know to only output "de los oficios" and not
"en castellano de los oficios"?

The obvious output from the above XML is:

  Séneca y Cicerón en casstellano de los oficios

(with the names clickable). You can get this with something like:

<xsl:template match="title">
  <xsl:apply-templates />
</xsl:template>

<xsl:template match="name">
  <xsl:variable name="nrEntrada"
                select="ancestor::itemInv/@n" />
  <a href="JavaScript:authorWindow('{$inventario}',{$nrEntrada});"
     class="linkAuthor">
    <xsl:value-of select="." />
  </a>
</xsl:template>

(Note that I'm not sure where the value of $inventario comes from.)

It sounds as though you want a hyphen to be added after the first text
node in <title> if it's got a following <name> sibling, and before the
last text node in <title> if it's got a preceding <name> sibling. You
can do this with the following two templates:

<xsl:template match="title/text()[1]">
  <xsl:value-of select="." />
  <xsl:if test="following-sibling::name"> - </xsl:if>
</xsl:template>

<xsl:template match="title/text()[last()]">
  <xsl:if test="preceding-sibling::name"> - </xsl:if>
  <xsl:value-of select="." />
</xsl:template>

This will give you (roughly):

  Séneca y Cicerón - en casstellano de los oficios

(Personally I think it's good practice to have mixed content contain
exactly the punctuation and whitespace that you want to have, rather
than letting it be added by a stylesheet later. Rules for adding
punctuation and whitespace in mixed content are horrible to maintain.)
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread