[Home] [By Thread] [By Date] [Recent Entries]
On 6/7/06, Neil Crofts <neil.crofts@xxxxxxxxx> wrote:
I'm trying to transform some XML which is supposed to act as an iterator/repeat statement without much success at the moment. I was wondering if anyone had some advice about the best way to approach this sort of problem. For example, my source XML looks a bit like the following:
Here is an XSLT 1.0 solution: <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/"> <output> <xsl:apply-templates select="input/repeat"/> </output> </xsl:template> <xsl:template match="repeat"> <xsl:variable name="this" select="."/> <xsl:for-each select="/input/data/item"> <item> <xsl:variable name="value" select="value"/> <xsl:variable name="pos" select="position()"/> <xsl:apply-templates select="$this/node()"> <xsl:with-param name="value" select="$value"/> <xsl:with-param name="pos" select="$pos"/> </xsl:apply-templates> </item> </xsl:for-each> </xsl:template> <xsl:template match="value-of"> <xsl:param name="value"/> <xsl:value-of select="$value"/> </xsl:template> <xsl:template match="position-of"> <xsl:param name="pos"/> <xsl:value-of select="$pos"/> </xsl:template> </xsl:stylesheet>
|

Cart



