将整数值转换为重复字符 [英] Transform an integer value to a repeated character
本文介绍了将整数值转换为重复字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我的 XSL 样式表遇到这个节点时:
When my XSL stylesheets encounters this node:
<node attribute="3"/>
...它应该把它转换成这个节点:
...it should transform it into this node:
<node attribute="***"/>
我的模板匹配属性并重新创建它,但我不知道如何将值设置为:字符*"重复的次数与原始属性的值一样多.
My template matches the attribute and recreates it, but I don't know how to set the value to: the character '*' repeated as many times as the value of the original attribute.
<xsl:template match="node/@attribute">
<xsl:variable name="repeat" select="."/>
<xsl:attribute name="attribute">
<!-- What goes here? I think I can do something with $repeat... -->
</xsl:attribute>
</xsl:template>
谢谢!
推荐答案
一个相当肮脏但实用的方法是调用你期望在 attribute
中看到的最高数字,然后使用
A fairly dirty but pragmatic approach would be to make a call on what's the highest number you ever expect to see in attribute
, then use
substring("****...", 1, $repeat)
您在该字符串中的 *
数量与您期望的最大数量一样多.但我希望有更好的东西!
where you have as many *
s in that string as that maximum number you expect. But I hope that there's something better!
这篇关于将整数值转换为重复字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文