O'Reilly logo

XSLT Cookbook by Sal Mangano

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating Generic Node-Set Generators

Problem

You want to create reusable templates for generating a node set computationally.

Solution

The first generic function in this category generates a node set by executing a function over successive values, as defined by an incrementing function, until an upper bound is reached:

<xsl:template name="generic:gen-set"> <xsl:param name="x" select="1"/> <xsl:param name="func" select=" 'identity' "/> <xsl:param name="func-param1" select="$generic:generics[self::generic:func and @name = $func]/@param1"/> <xsl:param name="test-func" select=" 'less-than' "/> <xsl:param name="test-param1" select="$x + 1"/> <xsl:param name="incr-func" select=" 'incr' "/> <xsl:param name="incr-param1" select="1"/> <xsl:param name="i" select="1"/> <xsl:param name="result" select="/.."/> <!-- Check if aggregation should continue --> <xsl:variable name="continue"> <xsl:apply-templates select="$generic:generics[self::generic:func and @name = $test-func]"> <xsl:with-param name="x" select="$x"/> <xsl:with-param name="param1" select="$test-param1"/> </xsl:apply-templates> </xsl:variable> <xsl:choose> <xsl:when test="string($continue)"> <!--Compute func($x) --> <xsl:variable name="f-of-x"> <xsl:apply-templates select="$generic:generics[self::generic:func and @name = $func]"> <xsl:with-param name="x" select="$x"/> <xsl:with-param name="i" select="$i"/> <xsl:with-param name="param1" select="$func-param1"/> </xsl:apply-templates> </xsl:variable> <!-- Compute the next value of ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required