RE: [xsl] 2 columns with special conditions

Subject: RE: [xsl] 2 columns with special conditions
From: "Bjorndahl, Brad" <brad.bjorndahl@xxxxxxxxxxxxxxxx>
Date: Fri, 4 May 2007 10:02:23 -0400
Hi,
I expected my solution could be made shorter like this.

I think this is another example of a characteristic of XSLT. You can put
the complexity into the logic (e.g. nested choose instructions) or in
the template structure or in XPATH, or in combinations of these.

As you gain experience with XSLT, you go through problem solving stages:
1. Frustration - cannot find any solution
2. Happy - found a solution
3. Happier - found 3 solutions and coded the easiest
4. Happiest - found 3 solutions and coded the cleverest/shortest/coolest
5. Frustration - found a 4th solution and spent a weekend re-coding

Brad


-----Original Message-----
From: George Cristian Bina [mailto:george@xxxxxxxxxxxxx]
Sent: May 4, 2007 6:57 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] 2 columns with special conditions

Hi Sven,

Looking more into this it seems that there is a quite simple solution:

<?xml version='1.0'?>
<xsl:transform version="1.0"
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:template match="steps">
     <table border="1">
       <xsl:apply-templates/>
     </table>
   </xsl:template>
   <xsl:template match="mc[@type='F']">
     <tr>
       <td><xsl:value-of select="@name"/></td>
       <td><xsl:value-of
select="following-sibling::*[1][@type='C']/@name"/></td>
     </tr>
   </xsl:template>
   <xsl:template
match="mc[@type='C'][not(preceding-sibling::*[1][@type='F'])]">
     <tr>
       <td></td>
       <td><xsl:value-of select="@name"/></td>
     </tr>
   </xsl:template>
</xsl:transform>

Regards,
George
---------------------------------------------------------------------
George Cristian Bina - http://aboutxml.blogspot.com/ <oXygen/> XML
Editor, Schema Editor and XSLT Editor/Debugger http://www.oxygenxml.com

Current Thread