P
patrik.nyman
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:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput 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.
/Patrik Nyman
<?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:xsl="http://www.w3.org/1999/XSL/Transform">
<xslutput 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.
/Patrik Nyman