#### Topic: How in xslt to transform in advance unknown kol-in columns in the table?

Certainly on mind at once comes to use a cycle:

&lt;xsl:for-each
select = Expression
&lt;/xsl:for-each&gt;

For example, it is necessary to deduce the data on customers:

&lt;customers&gt;
&lt;customer&gt;
&lt;name&gt; Vanja &lt;/name&gt;
&lt;phone&gt; (812 123-4567 &lt;/phone&gt;
&lt;/customer&gt;
&lt;customer&gt;
&lt;name&gt; Petja &lt;/name&gt;
&lt;phone&gt; (812 423-4537 &lt;/phone&gt;
&lt;/customer&gt;
&lt;/customers&gt;

That it to make, it is necessary to organize here such classical cycle:

&lt;xsl:for-each select = "customers/customer"&gt;
&lt;TR&gt;
&lt;TD&gt; &lt;xsl:value-of select = "name"/&gt; &lt;/TD&gt;
&lt;TD&gt; &lt;xsl:value-of select = "phone"/&gt; &lt;/TD&gt;
&lt;/TR&gt;
&lt;/xsl:for-each&gt;

As a result it is had necessary 2 columns:

Name Phone
--------------------
(812 123-4567
Petja (812 423-4537

But it is all for an output of the unknown person in advance kol-va lines and if it is not known kol-in columns?
For example, it is necessary to count kol-in made these clients of orders for the period set in the parameter that was here so:

Name Phone K1 K2 K3
----------------------------------
(812 123-4567 5 3 2
Petja (812 423-4537 2 4 7

In xslt I transfer as parameter kol-in columns, i.e. I know that this time them will be 3 (January, February and March). But how to write the universal code calculated for any value of this parameter?
Let's admit, columns in resultant , containing in orders on months will be named by a certain rule, for example so: QTY_1, QTY_2, QTY_3., QTY_N. And titles of columns in the total table too: 1, 2, 3..., N. (Where - kol-in columns, i.e. months, i.e. value transferred in xslt parameter).
How correctly to organize a cycle. It can be possible as that in a special way to use a tag colspan?

#### Re: How in xslt to transform in advance unknown kol-in columns in the table?

I would like to specify that on an input in conversion XSLT is available XML similar to it:

&lt;customers&gt;
&lt;customer&gt;
&lt;name&gt; Vanja &lt;/name&gt;
&lt;phone&gt; (812 123-4567 &lt;/phone&gt;
&lt;/customer&gt;
&lt;customer&gt;
&lt;name&gt; Petja &lt;/name&gt;
&lt;phone&gt; (812 423-4537 &lt;/phone&gt;
&lt;/customer&gt;
&lt;/customers&gt;

And on a conversion output it turns out HTML.
This input XML is formed dynamic (there is a XML file generator, in this generator it is transferred by parameter months), i.e. in the general schematical type it can will such:

&lt;customers&gt;
&lt;months_qty&gt; n &lt;/months_qty&gt;
&lt;customer&gt;
&lt;name&gt; Vanja &lt;/name&gt;
&lt;phone&gt; (812 123-4567 &lt;/phone&gt;
&lt;qty_1&gt; 5 &lt;qty_1&gt;
&lt;qty_2&gt; 3 &lt;qty_2&gt;
&lt;qty_3&gt; 2 &lt;qty_3&gt;
.....
&lt;qty_n&gt; x &lt;qty_n&gt;
&lt;/customer&gt;
&lt;customer&gt;
&lt;name&gt; Petja &lt;/name&gt;
&lt;phone&gt; (812 423-4537 &lt;/phone&gt;
&lt;qty_1&gt; 2 &lt;qty_1&gt;
&lt;qty_2&gt; 4 &lt;qty_2&gt;
&lt;qty_3&gt; 7 &lt;qty_3&gt;
.....
&lt;qty_n&gt; x &lt;qty_n&gt;
&lt;/customer&gt;
.................................
&lt;/customers&gt;

To process a node &lt;/customer&gt;, i.e. variable kol-in customers corresponding to lines &lt;TR&gt; - not a problem, we use a cycle &lt;xsl:for-each&gt;, and here is how to process variable kol-in orders at each customer on the months, corresponding to a cell in line &lt;TD&gt;?
In XSLT conversion I will know in months thanks to a tag &lt;months_qty&gt; from initial XML.

#### Re: How in xslt to transform in advance unknown kol-in columns in the table?

All is simple. Cycles are organized by a recursion, reversal to a dynamic name through a construction

*[name () =....]

[spoiler]

&lt;xsl:template match = "customers"&gt;
&lt;table border = "1"&gt;
&lt;xsl:variable name = "count" select = "months_qty"/&gt;
&lt;tr&gt;
&lt;th&gt; Name &lt;/th&gt;
&lt;th&gt; Phone &lt;/th&gt;
&lt;xsl:call-template name = "printHeaders"&gt;
&lt;xsl:with-param name = "idx" select = "\$ count"/&gt;
&lt;/xsl:call-template&gt;
&lt;/tr&gt;
&lt;xsl:apply-templates select = "customer"&gt;
&lt;xsl:with-param name = "count" select = "\$ count"/&gt;
&lt;/xsl:apply-templates&gt;
&lt;/table&gt;
&lt;/xsl:template&gt;
&lt;xsl:template match = "customer"&gt;
&lt;xsl:param name = "count"/&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;xsl:value-of select = "name"/&gt;
&lt;/td&gt;
&lt;td&gt;
&lt;xsl:value-of select = "phone"/&gt;
&lt;/td&gt;
&lt;xsl:call-template name = "printData"&gt;
&lt;xsl:with-param name = "idx" select = "\$ count"/&gt;
&lt;/xsl:call-template&gt;
&lt;/tr&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name = "printHeaders"&gt;
&lt;xsl:param name = "idx"/&gt;
&lt;xsl:if test = "\$ idx&gt; 0"&gt;
&lt;xsl:call-template name = "printHeaders"&gt;
&lt;xsl:with-param name = "idx" select = "\$ idx - 1"/&gt;
&lt;/xsl:call-template&gt;
&lt;th&gt;
&lt;xsl:value-of select = "concat (' K ', \$idx)"/&gt;
&lt;/th&gt;
&lt;/xsl:if&gt;
&lt;/xsl:template&gt;
&lt;xsl:template name = "printData"&gt;
&lt;xsl:param name = "idx"/&gt;
&lt;xsl:if test = "\$ idx&gt; 0"&gt;
&lt;xsl:call-template name = "printData"&gt;
&lt;xsl:with-param name = "idx" select = "\$ idx - 1"/&gt;
&lt;/xsl:call-template&gt;
&lt;td&gt;
&lt;xsl:value-of select = "* [name () = concat (' qty _ ', \$idx)]"/&gt;
&lt;/td&gt;
&lt;/xsl:if&gt;
&lt;/xsl:template&gt;

[/spoiler]

#### Re: How in xslt to transform in advance unknown kol-in columns in the table?

[quote = _ Vasilisk _] All is simple. Cycles are organized by a recursion, reversal to a dynamic name through a construction [code]
*[name () =....]

Thanks! I will try to apply.