Re: [xsl] Check if next tag is ...

Subject: Re: [xsl] Check if next tag is ...
From: "Anne Kootstra" <anne@xxxxxxxxx>
Date: Fri, 15 Dec 2006 15:21:00 +0100
Thank you all for your help and input. The different solutions for the same problem have given me a good understanding of how deep my understanding of XSLT is.

Michael, thanks for your view and solutions. I will try both notations in the not too distant future since they are a little beyond my current XPath capabilities. This is something I will read up upon.

Kind regards,

Anne.

----- Original Message ----- From: "Michael Kay" <mike@xxxxxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, December 15, 2006 12:20 PM
Subject: RE: [xsl] Check if next tag is ...



You can test if the next sibling element is a T element using

test="following-sibling::*[1][self::T]"

However, I wouldn't solve this problem in that way. I would have logic
something like

<xsl:template match="C">
 <tr>
   <td><xsl:value-of select="P"/></td>
   <td><xsl:value-of select="(T, '*')[1]"/></td>
   <td><xsl:value-of select="S"/></td>
 </tr>
</xsl:template>

In 1.0 you would have to expand this out using xsl:choose.

Michael Kay
http://www.saxonica.com/


-----Original Message-----
From: Anne Kootstra [mailto:anne@xxxxxxxxx]
Sent: 15 December 2006 07:38
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] Check if next tag is ...

The XML file I work with contains records that most of the
time have three unique nodes. However, it is part of the
design that one of these nodes, T in the example, is
optional. Here is an example of a file.

<A>
 <C>
   <P>AAA</P>
   <T>BBB</T>
   <S>CCC</S>
 </C>
 <C>
   <P>DDD</P>
   <T>EEE</T>
   <S>FFF</S>
 </C>
 <C>
   <P>GGG</P>
   <S>HHH</S>
 </C>
</A>

The end result I'm aiming for is a rather simpel HTML table:

            P            T            S
C        AAA       BBB       CCC
C        DDD       EEE       FFF
C        GGG         *          HHH
C          ....          ...            ....

The problem I'm having is that I'm trying to test when
processing the P node if the next node is T. If the next node
isn't T or if the T node doesn't exist then use the value *
instead. Now I've experiemented with following-sibling,
node() and value but haven't been successful.

Can anyone point me in the direction of a good tutorial or
help me out.
My current list of references during development are:
[1] - http://www.zvon.org/xxl/XSLTreference/Output/index.html,
[2] - http://www.dpawson.co.uk/xsl/sect2/sect21.html=20
But these haven't been able to help me do what I want to do.

Any help is welcomed.

Regards,

Anne.

Current Thread