Aron,
the reason why this code you suggest doesn't work is that my inputs are declared as
<input type="radio" id="{generate-id()}" name="{$id}" value="{(_at_)value}">
and the generate-id() functions probably loses reference to the context node when used inside
the <xsl:template match="opt">(now fi:item) as you suggested.
I adapted your snippets to produce this:
<xsl:for-each select="fi:selection-list/fi:item[position() <=
current()/$line]">
<xsl:variable name="r" select="position() - 1"/>
<tr>
<xsl:apply-templates select="fi:item[position() >= $r *
$column + 1
and position() <= $r * $column + $column ]"/>
</tr>
</xsl:for-each>
(...)
<xsl:template match="fi:item">
<td>
<input type="radio" id="{generate-id()}" name="{$id}"
value="{(_at_)value}">
(...)
</xsl:template>
Also the output i'm trying to achieve is e.g. for a table with 2 lines and
2 columns is
<td>
<input>
</td>
<td>
<input>
</td>
<tr> <!--I can only have (($number_of_lines) - 1) tr tags -->
<td>
<input>
</td>
<td>
<input>
</td>
</tr>
TIA and TG(Thanks again),
CarlosN.
On Sun, 12 Jun 2005, Aron Bock wrote:
Carlos,
I believe the prior respondent mentioned 2
ways to achieve what you want:
recursively write out rows and col or, if using for-each, supply for the
"rows" a nodeset equal to the number of @lines. The second approach is
described below (and for simplicity we derive # cols ):
With this input:
<data>
<radio line="1">
<opt>Masc</opt>
<opt>Fem</opt>
<opt>other</opt>
<opt>Masc2</opt>
<opt>Fem2</opt>
<opt>other2</opt>
</radio>
</data>
This XSL:
<?xml version="1.0" encoding="iso8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="radio">
<table>
<xsl:variable name="numcols" select="count(opt) div @line"/>
<xsl:for-each select="opt[position() <= current()/@line]">
<xsl:variable name="r" select="position() - 1"/>
<tr>
<xsl:apply-templates select="../opt[position() >= $r *
$numcols + 1
and position() <= $r * $numcols + $numcols ]"/>
</tr>
</xsl:for-each>
</table>
</xsl:template>
<xsl:template match="opt">
<td><xsl:value-of select="."/></td>
</xsl:template>
</xsl:stylesheet>
produces:
<?xml version="1.0" encoding="UTF-8"?>
<table>
<tr>
<td>Masc</td>
<td>Fem</td>
<td>other</td>
<td>Masc2</td>
<td>Fem2</td>
<td>other2</td>
</tr>
</table>
If you change @lines to 2, you should get 2 rows.
This may not work for @lines = sqrt( 2 )
Regards,
--A
From: "Carlos M. S. Bento Nogueira"
<cmsbn(_at_)student(_dot_)dei(_dot_)uc(_dot_)pt>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] Can not convert number to a NodeList
Date: Sun, 12 Jun 2005 03:00:36 +0100 (WEST)
I believed Michael Kay pointed the solution i'll use(switch to xslt 2.0).
I will be testing if and how i can use xslt 2.0 with apache cocoon 2.1.7.
What i basically wanted was to insert as many <tr> tags as lines and as
many <td> tags as columns
between the list elements. I cannot do it neither on form1.xml nor on
form1_template_action.xml(here the elements on form1 are called).
The line and column parameters are being passed from
form1_template_action.xml
to forms-field-styling.xsl.
Note that i also cannot insert <line> or <row> tabs between elements on
form1.xml.
form1.xml
<fd:widget>
(..)
<fd:field id="sexo_opcoes">
<fd:selection-list>
<fd:item value="Masc."/>
<fd:item value="Fem."/>
<fd:item value="Other."/>
-----------------------------------------------------
form1_template_action.xml
<fi:group>
<fi:styling type="tabs"/>
<fi:items>
<fi:group> (each group represents one tab)
(...)
<table border="0">
<tr>
<td>
<ft:widget id="sexo_opcoes">
<fi:styling list-type="radio" list-orientation="horizontal" line="1"
column="3">
(...)
---------------------------------------------------
forms-field-styling.xsl
<xsl:stylesheet version="1.0"....>
<xsl:template
match="fi:field[fi:selection-list][fi:styling/@list-type='radio']"
priority="2">
<xsl:variable name="column" select="number(fi:styling/@column)"/>
<xsl:variable name="line" select="number(fi:styling/@line)"/>
(...)
<xsl:for-each select="$line">
<xsl:for-each select="$column">
<td><xsl:text>C</xsl:text></td>
</xsl:for-each>
<xsl:if test="$line>1">
<tr><xsl:text>L</xsl:text></tr>
</xsl:if>
</xsl:for-each>
----------------------------------------------------------
Desired HTML output example:
(...)
<table border="0">
<tr>
<td>
label: sexo
</td>
<td>
Masc.
</td>
<td>
Fem.
</td>
<td>
Other
</td>
Thanks for your support and time,
CarlosN.
On Sat, 11 Jun 2005, Aron Bock wrote:
Carlos, you may want to include the relevant snippet of your input XML,
desired output, and your calling environment since you say " this
variables are numbers that must be passed to my xsl file."
Regards,
--A
_________________________________________________________________
Express yourself instantly with MSN Messenger! Download today - it's FREE!
http://messenger.msn.click-url.com/go/onm00200471ave/direct/01/
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--
--~------------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--