[英]XSLT: Concatenate a string n times
I want to concatenate a string for n times and set it as variable using XSLT 2.0.我想连接一个字符串 n 次并使用 XSLT 2.0 将其设置为变量。 The string to be concatenated is
../
, n is available as number in a variable.要连接的字符串是
../
, n 可用作变量中的数字。
I tried:我试过了:
<xsl:variable name="count-dirs" select="count(tokenize($target-filepath, '/')) - 1"/>
<xsl:variable name="path" select="''"/>
<xsl:for-each select="1 to $count-dirs"><xsl:variable name="path" select="concat($path, '../')"/></xsl:for-each>
I think you want eg <xsl:variable name="path" select="string-join((1 to $count-dirs).'.,/', '')"/>
in XSLT 3 or <xsl:variable name="path" select="string-join(for $i in 1 to $count-dirs return '../', '')"/>
in XSLT 2.我想你想要例如
<xsl:variable name="path" select="string-join((1 to $count-dirs).'.,/', '')"/>
in XSLT 3 或<xsl:variable name="path" select="string-join(for $i in 1 to $count-dirs return '../', '')"/>
in XSLT 2.
Life can be so easy...生活可以如此简单...
<xsl:variable name="count-dirs" select="count(tokenize($target-filepath, '/')) - 1"/>
<xsl:variable name="path">
<xsl:for-each select="1 to $count-dirs">../</xsl:for-each>
</xsl:variable>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.