固定长度的填充值 - xslt [英] Pad Value with fix length - xslt
问题描述
我有这个简单的 xslt 代码:
I have this simple xslt code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" indent="yes"/>
<xsl:template match="/racine/Requete">
<xsl:for-each select="Row">
<xsl:value-of select="Col[@name = 'Service Point']/." />
<xsl:text>ME02</xsl:text>
<xsl:value-of select="Col[@name = 'Meter Number']/." />
<xsl:value-of select="Col[@name = 'Date']/." />
<xsl:value-of select="translate(Col[@name = 'Import Active kWh']/.,',','.')" />
<xsl:text>30000000000000000000</xsl:text>
<xsl:text> </xsl:text>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Meter Number 参数最多可以有 10 个字母数字.因此,例如,如果值是 232345,我想显示(用空格填充):'232345'.我对 Import Active kWh 有同样的情况,这是一个数字字段修复 12 类型的数字,但如果值为 56884,我想显示(以 0 开头)'000000056884'.
The Meter Number parameter can have max 10 alphanumeric. so if for example the value is 232345, I want to display (pad with spaces):' 232345'. I have the same case for Import Active kWh, this is a numeric field fix 12 type numeric, but if the value is 56884, I want to display (pad with 0 at the begining) '000000056884'.
感谢您一如既往的有用帮助!
Thanks for your useful help as usual!
问候.
推荐答案
对于数字字段,您可以简单地使用 format-number()
函数,例如:
For the numeric field you can simply use the format-number()
function, e.g.:
<xsl:value-of select="format-number($numeric-field, '000000000000')"/>
对于字母数字字段,请尝试:
For the alpha-numeric field, try:
<xsl:value-of select="substring(concat(' ', $alphanumeric-field), 1 + string-length($alphanumeric-field))" />
如果您需要多次执行此操作,请考虑将其重新编写为函数.
If you need to do it more than once, consider re-writing this as a function.
注意:这个位置步骤 /.
没有任何作用.
Note: this location step /.
doesn't do anything.
这篇关于固定长度的填充值 - xslt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!