首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >科学数字格式

科学数字格式
EN

Stack Overflow用户
提问于 2012-10-09 02:03:01
回答 1查看 324关注 0票数 1

Referenced from here

我正在尝试找到一种使用xslt 1.0版格式化科学数字的方法。我试着引用stockoverflow中的例子作为参考,但是我不能让它工作。任何帮助都是很棒的!

谢谢!

编辑:我希望所有这些数字都有相同的格式。

代码语言:javascript
复制
    <?xml version="1.0" encoding="utf-8"?>
    <?xml-stylesheet type="text/xsl" href="SNS.xslt"?>
    <Scientific_Numbers>
      <Section_1>
        <SN_1>1.0000234E-4</SN_1>
        <SN_1>1.0000353476E-4</SN_1>
      </Section_1>
      <Section_2>
        <SN_1>1.3400234E-4</SN_1>
        <SN_1>0.0000234E-2</SN_1>
      </Section_2>
      <Section_3>
        <SN_1>1.003453453400234E-2</SN_1>
        <SN_1>1.0234E+6</SN_1>
      </Section_3>
    </Scientific_Numbers>

    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:template match="/">
    <html>
      <body>
        <h2>ScientificNumbers</h2>
        <xsl:apply-templates/>
      </body>
    </html>
    </xsl:template>

  <xsl:template match="Scientific_Numbers">
    <xsl:apply-templates select="SN_1"/>
    <br/>
  </xsl:template>


    <?xml version="1.0" encoding="utf-8"?>

    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
      <xsl:template match="/">
        <html>
          <body>
           <h2>Testing</h2>
           <xsl:apply-templates/>
          </body>
        </html>
      </xsl:template>

      <xsl:template match="Scientific_Numbers">
        <xsl:apply-templates select="SN_1"/>
        <br/>
      </xsl:template>

      <xsl:template match="SN_1[substring-after(.,'E')]">
        <xsl:variable name="vExponent" select="substring-after(.,'E')"/>
        <xsl:variable name="vMantissa" select="substring-before(.,'E')"/>
        <xsl:variable name="vFactor"              
                  select="substring('100000000000000000000000000000000000000000000',
                  1, substring($vExponent,2) + 1)"/>
    <xsl:choose>
      <xsl:when test="starts-with($vExponent,'-')">
        <xsl:value-of select="$vMantissa div $vFactor"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$vMantissa * $vFactor"/>
      </xsl:otherwise>
    </xsl:choose>
      </xsl:template>
    </xsl:stylesheet>
EN

回答 1

Stack Overflow用户

发布于 2012-10-09 04:29:51

XSLT 1.0中没有以科学记数法输出数字的机制(事实上,即使在XSLT 2.0中也有有限的功能)。您必须了解您的XSLT处理器支持哪种扩展机制。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12787071

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档