科学记数法和数字序列

问题描述 投票:0回答:2

在片段下面输出给定序列中缺少的数字。它适用于小数,但不适用于科学记数法(即1.6646144E7)。如何解决这个问题?

  <xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs">
<xsl:template match="/">
    <xsl:variable name="OriginalSequence">16646145 1.6646144E7 16646149 1.6646148E7 16646151 1.664615E7 16646163 1.6646162E7</xsl:variable>        
    <!--<xsl:variable name="OriginalSequence">1 2 8 2 3</xsl:variable>-->
    <xsl:variable name="seq1" as="xs:integer*" select="for $s in $OriginalSequence/tokenize(normalize-space(.), '\s+') return xs:integer($s)"/>
    <xsl:variable name="seq2" as="xs:integer*"  select="min($seq1) to max($seq1)"/>
    <xsl:variable name="seq3" as="xs:integer*" select="$seq2[not(. = $seq1)]"/>
    <missing><xsl:value-of select="$seq3"/></missing>       
</xsl:template>

期望的输出:

  <missing>16646145 16646146 16646147 16646152 16646153 16646154 16646155 16646156 16646157 16646158 16646159 16646160 16646161</missing>

变量originalSequence是我原来的xslt中算术运算的输出,我不确定我是否可以告诉xslt2.0不要转换成科学记数法?

xslt xslt-2.0
2个回答
1
投票

作为样本中的修复,您可以使用xs:integer(xs:double($s))而不是直接尝试xs:integer($s)。但是,如果您的真实代码首先创建xs:doubles而不是xs:integers,您可能只需更改该代码即可创建整数。这取决于您拥有和尚未共享的代码。


0
投票

我不确定我是否可以告诉xslt2.0不要转换成科学记数法?

是的,您可以使用format-number()函数来获得您想要的格式。对于1e-6到1e + 6范围之外的数字,默认的数字到字符串转换使用指数表示法。

© www.soinside.com 2019 - 2024. All rights reserved.