英文:
Padding with spaces and number formatting XSLT 1.0
问题
I understand your request. Here's the translated code part:
<Weight><xsl:value-of select="format-number(Weight,'###### ')"/></Weight>
Expected output:
<Weight> 1150</Weight>
Current Output:
<Weight>001150</Weight>
英文:
Im trying to reformat weight values to not have any decimal places and always have six characters. Ive managed to work out how to pad with zeros but i cant seem to make it work with spaces. Any ideas?
Input:
<Weight>1150.0</Weight>
xlst:
<Weight><xsl:value-of select="format-number(Weight,'######')"/></Weight>
Expected output:
<Weight> 1150</Weight>
Current Output:
<Weight>001150</Weight>
答案1
得分: 0
这是一种方法:
<xsl:variable name="int" select="round(Weight)"/>
<xsl:value-of select="substring(concat(' ', $int), 1 + string-length($int))"/>
如果您的处理器支持,您可以使用EXSLT str:align()
扩展函数:
<xsl:value-of select="str:align(round(Weight), ' ', 'right')"/>
请注意,当整数具有超过6位数字时,这两种方法的行为会有所不同。
英文:
Here is one way:
<xsl:variable name="int" select="round(Weight)"/>
<xsl:value-of select="substring(concat(' ', $int), 1 + string-length($int))"/>
If your processor supports it, you could use the EXSLT str:align()
extension function:
<xsl:value-of select="str:align(round(Weight), ' ', 'right')"/>
Note that the two methods will behave differently when the integer has more than 6 digits.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论