Jan Jan - 6 months ago 49
HTML Question

Dynamic HTML Table with XSLT

I need to loop over a group of values and print them into a two-column table.

I thought about following solution (must be xslt1)

<table class="main">

<xsl:for-each select="Attribute/Gruppe">
<xsl:if test="current()/@ID=20064490">
<xsl:variable name="open_row"><![CDATA[<tr><td style="width:50%;">
<xsl:value-of select="current()/@name" /></td>]]></xsl:variable>
<xsl:variable name="closing_row"><![CDATA[<td style="width:50%;">
<xsl:value-of select="current()/@name" /></td></tr>]]></xsl:variable>

<xsl:variable name="table">
<xsl:for-each select="*">
<xsl:when test="(position() mod 2) = 1">
<xsl:value-of select="$open_row"
disable-output-escaping="yes" />


<xsl:value-of select="$closing_row"
disable-output-escaping="yes" />

<xsl:value-of select="$table"
disable-output-escaping="yes" />

I modified the code now I am using
to find out if an closing
or an opening
is required.

The whole problem might be summarized to that you can not write single tags in XSLT. And that
is not working.

Resulting HTML should be https://jsfiddle.net/dwetctm6/

For all the Nodes in the group. The order of the nodes in the table does not matter.

Furthermore assume following XML:

<NODE n-1>text</NODE n-1>
<NODE n>text</NODE n>


Dividing nodes into a two-column table is pretty trivial - especially if the order (across-first or down-first) does not matter.

Consider the following stylesheet:

XSLT 1.0

<xsl:stylesheet version="1.0"
<xsl:output method="xml" omit-xml-declaration="yes" version="1.0" encoding="utf-8" indent="yes"/>

<xsl:template match="/bgroup">
    <table border="1">
        <xsl:for-each select="*[position() mod 2 = 1]">
                <td><xsl:value-of select="."/></td>
                <td><xsl:value-of select="following-sibling::*[1]"/></td>


Applied to the following well-formed inpout:



the result will be:

<table border="1">

rendered as:

enter image description here