incorrect position() in xsl:apply-templates
Added by Anonymous almost 19 years ago
Legacy ID: #3537124 Legacy Poster: cin (cinsin)
HI, I'm using saxon 8.6.1, jdk1.4.2 on win XP, and I am trying to set some properties differently according the the node number within a node set. I use position() within an xsl:apply-templates to detected whether this is the first or last node. The result is that position() always returns 1, but it should return the current context position, shouldn't it? Here a snippet of my test code, and further down the output: ... <xsl:template match="ReportContent" mode="order-entries"> <xsl:apply-templates select="//ColumnHeader[@level=1]" mode="level-one"> <xsl:with-param name="pos" select="position()"/> <xsl:with-param name="last" select="last()"/> <xsl:with-param name="border-left"> <xsl:choose><xsl:when test="position()=1"><xsl:value-of select="'0.5pt solid #cccccc'"/></xsl:when> <xsl:otherwise><xsl:value-of select="'0.5pt solid #e4e4e4'"/></xsl:otherwise> </xsl:choose> </xsl:with-param> <xsl:with-param name="border-right"> <xsl:choose><xsl:when test="position()=last()"><xsl:value-of select="'0.5pt solid #cccccc'"/></xsl:when> <xsl:otherwise><xsl:value-of select="'0.5pt solid #e4e4e4'"/></xsl:otherwise> </xsl:choose> </xsl:with-param> </xsl:apply-templates> </xsl:template> <xsl:template match="ColumnHeader" mode="level-one"> <xsl:param name="border-left"/> <xsl:param name="border-right"/> <xsl:param name="pos"/> <xsl:param name="last"/> <xsl:variable name="current-header" select="current()"/> <fo:block> <xsl:value-of select="$current-header"/>,<xsl:value-of select="$pos"/>,<xsl:value-of select="$last"/> </fo:block> </xsl:template> ... Here some of the output: .... <fo:flow flow-name="body"> <fo:block>Germany,1,1</fo:block> <fo:block>France,1,1</fo:block> <fo:block>Germany,1,1</fo:block> <fo:block>France,1,1</fo:block> <fo:block>France,1,1</fo:block> <fo:block>France,1,1</fo:block> <fo:block>France,1,1</fo:block> <fo:block>Germany,1,1</fo:block> <fo:block>Germany,1,1</fo:block> <fo:block>Germany,1,1</fo:block> .... Many thanks for any help Cinzia
Replies (2)
RE: incorrect position() in xsl:apply-templat - Added by Anonymous almost 19 years ago
Legacy ID: #3537157 Legacy Poster: Michael Kay (mhkay)
The context item, position, and size when evaluating xsl:with-param are the same as when evaluating the select expression of the containing xsl:apply-templates: see http://www.w3.org/TR/xslt20/#with-param Think of it this way: the parameters are evaluated before the loop starts, and the same parameter values are passed to each template that gets invoked. That template can then use position() to find out which of the nodes is being processed. Michael Kay
RE: incorrect position() in xsl:apply-templates - Added by Anonymous almost 19 years ago
Legacy ID: #3537188 Legacy Poster: cin (cinsin)
what an angel, thank you very much.
Please register to reply