Alex Rivera | Logout

How to show a character n times in XSLT?

Asked 2011-02-23T09:34:29.997
18

I have a template with a parameter. How can I insert a tab character n times?

n is the value of the parameter.

Edit
Report

1 Answer

15

In XSLT 2.0:

<xsl:for-each select="1 to $count">&#x9;</xsl:for-each>

(Sadly though, I suspect that if you were using XSLT 2.0 you wouldn't need to ask the question).

Another technique often used with XSLT 1.0 is the hack:

<xsl:for-each select="//*[position() &lt;= $count]">&#x9;</xsl:for-each>

which works provided the number of elements in your source document is greater than the number of tab characters you want to output.

answered 2011-02-23T12:03:51.860

Your Answer