I've got a series of documents in my XML data. The documents have a given width. I need to style the documents so the documents with a width of 100 are in their own line while other documents are grouped two in a line. There is always a maximum of 2 columns so it's not possible to have 3 documents with a width of 33 in one line.
So I want my data.xml to results in the following:
<div class="row">
<div>DocumentA</div>
</div>
<div class="row">
<div>DocumentB</div>
<div>DocumentC</div>
</div>
<div class="row">
<div>DocumentD</div>
<div>DocumentE</div>
</div>
- data.xml -
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<documents>
<document>
<width>100</width>
<content>Document A</content>
</document>
<document>
<width>66</width>
<content>Document B</content>
</document>
<document>
<width>33</width>
<content>Document C</content>
</document>
<document>
<width>50</width>
<content>Document D</content>
</document>
<document>
<width>50</width>
<content>Document E</content>
</document>
</documents>
- style.xsl -
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="document"> <html> <head> <title>XSLT</title> </head> <body> <xsl:choose> <xsl:when test="width=100"> <div class="row"> <div><xsl:value-of select="content"/></div> </div> </xsl:when> <!-- Pseudo begin --> <xsl
therwise> <div class="row"> <div><xsl:value-of select="this.content"/></div> <div><xsl:value-of select="next.content"/></div> next.skip </div> </xsl
therwise> <!-- Pseudo end --> </xsl:choose> </body> </html> </xsl:template> </xsl:stylesheet
So I want my data.xml to results in the following:
<div class="row">
<div>DocumentA</div>
</div>
<div class="row">
<div>DocumentB</div>
<div>DocumentC</div>
</div>
<div class="row">
<div>DocumentD</div>
<div>DocumentE</div>
</div>
- data.xml -
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="style.xsl"?>
<documents>
<document>
<width>100</width>
<content>Document A</content>
</document>
<document>
<width>66</width>
<content>Document B</content>
</document>
<document>
<width>33</width>
<content>Document C</content>
</document>
<document>
<width>50</width>
<content>Document D</content>
</document>
<document>
<width>50</width>
<content>Document E</content>
</document>
</documents>
- style.xsl -
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="document"> <html> <head> <title>XSLT</title> </head> <body> <xsl:choose> <xsl:when test="width=100"> <div class="row"> <div><xsl:value-of select="content"/></div> </div> </xsl:when> <!-- Pseudo begin --> <xsl