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

Subject: Re: [xsl] Check if next tag is ...
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Fri, 15 Dec 2006 10:50:20 +0100
Anne Kootstra wrote:

 You can use something like this (but you didn't say if you are using
XSLT 1.0 or 2.0):

I intent to stick to 1.0.


       <xsl:apply-templates select="
           P, if ( T ) then T else $empty-t, S"/>

Cheers, I will give this a go.

This only works on XSLT 2.0. In XSLT 1.0, you might try it like this (this is a non-generalized approach. Depending on your real input data, you may want other approaches):


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
<xsl:output method="xml" indent="yes"/>


   <xsl:template match="/A">
       <table>
       <xsl:apply-templates select="C" />
       </table>
   </xsl:template>
   <xsl:template match="C[not(T)]">
       <tr>
           <xsl:apply-templates select="P" />
           <td>*</td>
           <xsl:apply-templates select="S" />
       </tr>
   </xsl:template>
   <xsl:template match="C">
       <tr>
           <xsl:apply-templates select="*" />
       </tr>
   </xsl:template>
   <xsl:template match="P|S|T">
       <td><xsl:value-of select="."/></td>
   </xsl:template>
</xsl:stylesheet>

I tested the above template with your input. It gives the desired result (I used html tags, not sure if that's what you need).

Cheers,

Abel Braaksma
Nuntia B.V.

Current Thread