2012-10-08 2 views
1

Referenced from here과학 숫자 서식

xslt 버전 1.0을 사용하여 과학 숫자의 서식을 지정하는 방법을 찾으려고합니다. 참조로 스톡 오버 플로우의 예제를 사용하려고 시도했지만 작동하지 않습니다. 어떤 도움이 굉장 할 것입니다!

감사합니다.

편집 :이 숫자가 모두 같은 형식으로되어 있어야합니다. 과학적 표기법으로 출력 번호에 XSLT 1.0 메커니즘이 없습니다

<?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> 
+0

http://stackoverflow.com/questions/4367737/formatting-scientific-number-representation-in-xsl – ABach

+0

@ABach, 감사합니다.하지만 이미 내 질문에 해당 게시물을 연결했습니다. 그 게시물은 내가 참조로 사용하고 있으며 그것을 구현하는 방법을 알아낼 수 없습니다 correclty. – AD6

답변

0

(사실, 심지어는 XSLT 2.0 제한 기능이있다). XSLT 프로세서가 어떤 종류의 확장 메커니즘을 지원하는지 확인해야합니다.