in message < .com>,
('') wrote:
> Consider the following document:
>
> <?xml version="1.0"?>
> <!DOCTYPE test>
> <test>
> <list type="index">
> <item>A</item>
> <item>B</item>
> <item>C</item>
> <cb/>
> <item>D</item>
> <item>E</item>
> <item>F</item>
> </list>
> </test>
>
> I want to transform this to the following html:
>
> <table class="index">
> <td class="leftcolumn">
> <p class="item">A</p>
> <p class="item">B</p>
> <p class="item">C</p>
> </td>
> <td class="rightcolumn">
> <p class="item">D</p>
> <p class="item">E</p>
> <p class="item">F</p>
> </td>
> </table>
>
> For this I've been trying the following style sheet:
>
> <?xml version="1.0" encoding="utf-8"?>
> <xsl:stylesheet version="2.0"
> xmlns
sl="http://www.w3.org/1999/XSL/Transform">
> <xsl
utput method="html" indent="yes"/>
>
> <xsl:template match="list[@type='index']">
> <table class="index">
> <td class="leftcolumn">
> <xsl:for-each-group select="item"
> group-ending-with="item[following-sibling::cb]">
> <xsl:apply-templates select="current-group()"/>
> </xsl:for-each-group>
> </td>
> <td class="rightcolumn">
> <xsl:for-each-group select="item"
> group-starting-with="item[preceding-sibling::cb]">
> <xsl:apply-templates select="current-group()"/>
> </xsl:for-each-group>
> </td>
> </table>
> </xsl:template>
>
> <xsl:template match="item">
> <p class="item"><xsl:apply-templates/></p>
> </xsl:template>
>
> <xsl:template match="cb">
> <xsl:copy/>
> </xsl:template>
>
> </xsl:stylesheet>
>
> But this produces the following result:
>
> <table class="index">
> <td class="leftcolumn">
> <p class="item">A</p>
> <p class="item">B</p>
> <p class="item">C</p>
> <p class="item">D</p>
> <p class="item">E</p>
> <p class="item">F</p>
> </td>
> <td class="rightcolumn">
> <p class="item">A</p>
> <p class="item">B</p>
> <p class="item">C</p>
> <p class="item">D</p>
> <p class="item">E</p>
> <p class="item">F</p>
> </td>
> </table>
>
> Could someone please tell me what I'm doing wrong?
> Thanks.
No, because I wouldn't do it like that. Either you want to generate
<test>
<list type="index">
<cb>
<item>A</item>
<item>B</item>
<item>C</item>
</cb>
<cb>
<item>D</item>
<item>E</item>
<item>F</item>
<cb>
</list>
</test>
or you want
<xsl:variable name="split" select="count( item)/2"/>
<div class="leftcolumn">
<xsl:apply-templates select="item[position() <= $split]"/>
</div>
<div class="rightcolumn">
<xsl:apply-templates select="item[position() > $split]"/>
</div>
Alternately you could do something like:
<div class="contentcolumn">
<xsl:apply-templates select="//story[ not( @lead) and (position()
mod 3) = 0]">
<xsl:sort select="created[position()=1]/@iso-8601"
order="descending"/>
</xsl:apply-templates>
</div>
<div class="contentcolumn">
<xsl:apply-templates select="//story[ not( @lead) and (position()
mod 3) = 1]">
<xsl:sort select="created[position()=1]/@iso-8601"
order="descending"/>
</xsl:apply-templates>
</div>
<div class="contentcolumn">
<xsl:apply-templates select="//story[ not( @lead) and (position()
mod 3) = 2]">
<xsl:sort select="created[position()=1]/@iso-8601"
order="descending"/>
</xsl:apply-templates>
</div>
Yup, that's a genuine example. It does this:
<URL:http://www.stewartry-wheelers.org/wheelers/news>
--
(Simon Brooke)
http://www.jasmine.org.uk/~simon/
X-no-archive: No, I'm not *that* naive.