在XSLT 1.0中,使用空格进行填充和数字格式化。

huangapple go评论62阅读模式
英文:

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:

&lt;xsl:variable name=&quot;int&quot; select=&quot;round(Weight)&quot;/&gt;
&lt;xsl:value-of select=&quot;substring(concat(&#39;      &#39;, $int), 1 + string-length($int))&quot;/&gt;

If your processor supports it, you could use the EXSLT str:align() extension function:

&lt;xsl:value-of select=&quot;str:align(round(Weight), &#39;      &#39;, &#39;right&#39;)&quot;/&gt;

Note that the two methods will behave differently when the integer has more than 6 digits.

huangapple
  • 本文由 发表于 2023年6月29日 17:50:38
  • 转载请务必保留本文链接:https://go.coder-hub.com/76579938.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定