Xslt 科学数字格式
我试图找到一种使用xslt 1.0版格式化科学数字的方法。我试图使用stockoverflow的例子作为参考,但我无法让它工作。任何帮助都会很棒 谢谢 编辑:我希望所有这些数字具有相同的格式Xslt 科学数字格式,xslt,Xslt,我试图找到一种使用xslt 1.0版格式化科学数字的方法。我试图使用stockoverflow的例子作为参考,但我无法让它工作。任何帮助都会很棒 谢谢 编辑:我希望所有这些数字具有相同的格式 <?xml version="1.0" encoding="utf-8"?> <?xml-stylesheet type="text/xsl" href="SNS.xslt"?> <Scientific_Numbers> <Sec
<?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>
1.0000234E-4
1.0000353476E-4
1.3400234E-4
0.0000234E-2
1.003453453400234E-2
1.0234E+6
科学数字
测试
XSLT 1.0中没有以科学记数法输出数字的机制(事实上,即使在XSLT 2.0中也有有限的功能)。您必须了解XSLT处理器支持哪种扩展机制。@ABach,谢谢,但我已经在我的问题中链接了这篇文章。那篇文章是我用来作为参考的,我不知道如何正确地实现它。