Divide and multiply choice value in XSLT

I just want to multiply the -select value by 1,000,000 after the div, very new to this; I am sure this is a simple question for someone. Thanks in advance.

<xsl:value-of select="AbsolutePos/@x div 80" />

If you want to multiply by 1,000,000, donโ€™t think that itโ€™s right, so it returns the wrong value

<xsl:value-of select="AbsolutePos/@x div 80 * 1000000" />

Continued: enter the following XML

<AbsolutePos x="-1.73624e+006" y="-150800" z="40000"></AbsolutePos>

Change to

<PInsertion>-21703,-1885,500</PInsertion>

Using XSL

<PInsertion><xsl:value-of select="AbsolutePos/@x div 80 * 1000000" />,<xsl:value-of select="AbsolutePos/@y div 80" />,<xsl:value-of select="AbsolutePos/@z div 80" /></PInsertion>

Although getting

<PInsertion>NaN,-1885,500</PInsertion>

Suppose you take the value of X and divide it by 80, then multiply by 10,000 by the return of -21703

+4
source share
1 answer

If your XSLT processor does not recognize scientific notation, you will have to do this work yourself - for example:

XSLT 1.0

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="AbsolutePos">
    <PInsertion>
        <xsl:apply-templates select="@*"/>
    </PInsertion>
</xsl:template> 

<xsl:template match="AbsolutePos/@*">
    <xsl:variable name="num">
        <xsl:choose>
            <xsl:when test="contains(., 'e+')">
                <xsl:variable name="factor">
                    <xsl:call-template name="power-of-10">
                        <xsl:with-param name="exponent" select="substring-after(., 'e+')"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="substring-before(., 'e+') * $factor" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="." />
            </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>
    <xsl:value-of select="$num div 80" />
    <xsl:if test="position()!=last()">
        <xsl:text>,</xsl:text>
    </xsl:if>
</xsl:template>

<xsl:template name="power-of-10">
    <xsl:param name="exponent"/>
    <xsl:param name="result" select="1"/>
    <xsl:choose>
        <xsl:when test="$exponent">
            <xsl:call-template name="power-of-10">
                <xsl:with-param name="exponent" select="$exponent - 1"/>
                <xsl:with-param name="result" select="$result * 10"/>
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$result"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

</xsl:stylesheet>

, , .


() @x, #.####e+006, , substring-before(AbsolutePos/@x, 'e+') 12500 (.. 10 ^ 6/80).

+5

Source: https://habr.com/ru/post/1542117/


All Articles