A
Adam dR.
I have an xml file similar to:
<menu>
<menuitem name="home" show="false"/>
<menuitem name="about" show="true"/>
<menuitem name="links" show="true"/>
<menuitem name="games" show="true"/>
<menuitem name="learn" show="true"/>
<menuitem name="order" show="true"/>
<menuitem name="contact" show="true"/>
<menuitem name="support" show="false"/>
<menuitem name="feedback" show="true"/>
....
</menu>
What I am trying to achieve is a table that takes every four menuitems
that are show="true" and put them in a table row and then put each
menuitem is a <td>..
Desired output:
<table>
<tr>
<td>about</td>
<td>links</td>
<td>games</td>
<td>learn</td>
</tr>
<tr>
<td>order</td>
<td>contact</td>
<td>feedback</td>
</tr>
</table>
I cannot figure out how to loop four and place them in a <tr> tag
What I have tried:
<xsl:template match="/">
<table>
<xsl:apply-templates select="menu"/>
</table>
</xsl:template>
<xsl:template match="menu">
<xsl:for-each select="menuitem[@show='true']">
<xsl:if test="position() mod 4 = 1">
<xsl:text ><tr></xsl:text>
</xsl:if>
<td><xsl:value-of select="@name"/></td>
<xsl:if test="position() mod 4 = 0">
<xsl:text><tr></xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
There are a couple problems with this, 1. the position is still the
position of all menuitems true or false so I am not guaranteed 4 items
per row. 2. and most of all if actually right "<tr>" rather then
placing the <tr> tag in the html doc.
Any help would be great!
~Adam dR.
<menu>
<menuitem name="home" show="false"/>
<menuitem name="about" show="true"/>
<menuitem name="links" show="true"/>
<menuitem name="games" show="true"/>
<menuitem name="learn" show="true"/>
<menuitem name="order" show="true"/>
<menuitem name="contact" show="true"/>
<menuitem name="support" show="false"/>
<menuitem name="feedback" show="true"/>
....
</menu>
What I am trying to achieve is a table that takes every four menuitems
that are show="true" and put them in a table row and then put each
menuitem is a <td>..
Desired output:
<table>
<tr>
<td>about</td>
<td>links</td>
<td>games</td>
<td>learn</td>
</tr>
<tr>
<td>order</td>
<td>contact</td>
<td>feedback</td>
</tr>
</table>
I cannot figure out how to loop four and place them in a <tr> tag
What I have tried:
<xsl:template match="/">
<table>
<xsl:apply-templates select="menu"/>
</table>
</xsl:template>
<xsl:template match="menu">
<xsl:for-each select="menuitem[@show='true']">
<xsl:if test="position() mod 4 = 1">
<xsl:text ><tr></xsl:text>
</xsl:if>
<td><xsl:value-of select="@name"/></td>
<xsl:if test="position() mod 4 = 0">
<xsl:text><tr></xsl:text>
</xsl:if>
</xsl:for-each>
</xsl:template>
There are a couple problems with this, 1. the position is still the
position of all menuitems true or false so I am not guaranteed 4 items
per row. 2. and most of all if actually right "<tr>" rather then
placing the <tr> tag in the html doc.
Any help would be great!
~Adam dR.