[xsl] position() inside a for x to y

Subject: [xsl] position() inside a for x to y
From: "Rick Roen" <Rick@xxxxxxxxxxxxxxxxxx>
Date: Sun, 11 Jun 2006 06:06:13 -0500
XSLT 2.0 XPath 2.0 Saxon 8

I am creating an xml-fo file that has several options for table column
headers which are stored in variables like:

<xsl:variable name="colhead-size"
select="'1.5cm','1.5cm','1.5cm','proportional-column-width(1)','2cm','2cm','
2cm','2cm'"/>

Then, in the xslt I loop like this to create the fo:table-columns:


		<xsl:for-each select="1 to count($colhead-names)">
			<xsl:variable name="pos" select="position()"/>
			<fo:table-column>
				<xsl:attribute name="column-width"
select="$colhead-size[$pos]"/>
				<xsl:attribute name="text-align"
select="$colhead-align[$pos]"/>
				<xsl:attribute name="column-number"
select="$pos"/>
			</fo:table-column>
		</xsl:for-each>

This does work, however this does not work when I use the "position()"
directly:

		<xsl:for-each select="1 to count($colhead-names)">
			<fo:table-column>
				<xsl:attribute name="column-width"
select="$colhead-size[position()]"/>
				<xsl:attribute name="text-align"
select="$colhead-align[position()]"/>
				<xsl:attribute name="column-number"
select="$pos"/>
			</fo:table-column>
		</xsl:for-each>

This gives me the entire node set so I get:
	<fo:table-column column-width="1.5cm 1.5cm 1.5cm
proportional-column-width() 2cm etc." ...

My question is: why do I have to save position() to a variable to use it
properly in the for-each loop?

Rick

Current Thread