Re: [xsl] 2 columns with special conditions

Subject: Re: [xsl] 2 columns with special conditions
From: George Cristian Bina <george@xxxxxxxxxxxxx>
Date: Thu, 03 May 2007 17:29:09 +0300
Hi Sven,

Something like below should do it:

<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:template match="step"> <table> <xsl:apply-templates select="*[1]" mode="expectF"/> </table> </xsl:template>

<xsl:template match="mc[@type='F']" mode="expectF">
<tr>
<td><xsl:value-of select="@name"/></td>
<xsl:apply-templates select="following-sibling::*[1]" mode="expectC"/>
</tr>
<xsl:apply-templates mode="expectF" select="(following-sibling::*[1][@type='F']|following-sibling::*[2])[1]"/>
</xsl:template>


  <xsl:template match="mc[@type='C']" mode="expectF">
    <tr>
      <td>-</td>
      <td><xsl:value-of select="@name"/></td>
    </tr>
    <xsl:apply-templates select="following-sibling::*[1]" mode="expectF"/>
  </xsl:template>

  <xsl:template match="mc[@type='F']" mode="expectC">
    <td>-</td>
  </xsl:template>
  <xsl:template match="mc[@type='C']" mode="expectC">
    <td><xsl:value-of select="@name"/></td>
  </xsl:template>
</xsl:stylesheet>

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


Sven Waibel wrote:
Hi,

i have a "little" problem.
I try to get a two column layout where all elements with type F live in
column one and elements with type C in column two. Special thing is that
you have watch the order. How can i achieve case 2 and 3?

Thanks in advance
Sven

xml:
case1:

<mc name="1" type="F"/>
<mc name="2" type="C"/>
<mc name="3" type="F"/>
<mc name="4" type="C"/>
<mc name="5" type="F"/>
<mc name="6" type="C"/>

=>
(first column always type F, second type C)

1	2
3	4
5	6

there is no problem, template works.


case2:


<mc name="1" type="C"/>
<mc name="2" type="C"/>
<mc name="3" type="F"/>
<mc name="4" type="C"/>
<mc name="5" type="F"/>
<mc name="6" type="C"/>

=>

-	1
-	2
3	4
5	6


case3:


<mc name="1" type="F"/>
<mc name="2" type="C"/>
<mc name="3" type="F"/>
<mc name="4" type="F"/>
<mc name="5" type="F"/>
<mc name="6" type="C"/>

=>

1	2
3	-
4	-
5	6

my xsl:
....
<xsl:template match="step">
	<xsl:for-each select="descendant::mc[position() mod 2 = 1]">
		<tr>
			<td>
				<xsl:value-of select="self::node()[@type='F']/@name"/>
			</td>
			<td>
				<xsl:value-of select="following-sibling::node()[position()+1 and
@type='C']/@name"/>
			</td>
		</tr>
	</xsl:for-each>
</xsl:template>
...

Current Thread