Re: [xsl] Creating exception in processing a node

Subject: Re: [xsl] Creating exception in processing a node
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Thu, 02 Sep 2010 09:39:49 +0100
Write template rules like this:

<xsl:template match="p | p/name | p/title">
<!-- not really needed because this is the default -->
<xsl:apply-templates/>
</xsl:template>

<xsl:template match="note | bibl">
<!-- do nothing -->
</xsl:template>

Michael Kay
Saxonica

On 02/09/2010 9:21 AM, Gabor Tsth wrote:
Dear All,

I wish to process the content of the p element in the following xml
file, however, I would need the text, the content of the title and
author elements but not the bibl and the note element. Here is the
source:

<msItem>
                 <locus>1r-3v</locus>
                 <p>This is a sonette by<name>Mario Davanzati</name>,
titled<title>De Amicitia</title>.
                     <note type="friendship">This is an interesting
sonette about friendship</note>
                     <bibl>
                         <author>Mario Davanzati</author>
                         <title>De Amicitia</title>
                         <pubPlace>Florence</pubPlace>
                     </bibl></p>
             </msItem>

What I would like to see is:

Description: This is a sonette by Mario Davanzati, titled De Amicitia.

If I write a simple template like this, obviously it takes everything
including the bibl and note elements:

<xsl:template match="msItem">

         <h3>Description:</h3><xsl:apply-templates select="p"/>
   </xsl:template>
     <xsl:template match="p">
         <xsl:value-of select="."/>
   </xsl:template>

I tried with the | operator ( text() | title | author), but it did not
give the desired solution. I am wondering if there is something like
<xsl:value-of select=".[giving an exception here]"/>

The other part of the problem is that the order of the name, title
element and the text can be different, so<xsl:value-of
select="text()"/>  <xsl:value-of select="title"/>  and<xsl:value-of
select="name"/>, instead of<xsl:value-of select="."/>, does not help
much.

Thanks,

Gabor

Current Thread