[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Check if text is before an tag or not

Subject: Re: Check if text is before an tag or not
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Wed, 12 Nov 2003 13:41:29 +0000
xsl if text
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.