I need to add two columns using XSL

Asked

Viewed 41 times

0

Hello I need help to add two columns in a report. The below follows what I have already done: XML

-<MaterialCrossSects>

<MaterialCrossSect name="ATERRO - PISTA" cumVolume="0" volume="0" area="0"/>


-<MaterialCrossSect name="ATERRO - CALÇADA ESQUERDA" cumVolume="0" volume="0" area="0.022566610288095">


-<MaterialCrossSectEnvelop area="1.64352610684091E-02">

<CrossSectPnt OE=" -4.249904, 892.028701"/>

<CrossSectPnt OE=" -4.249800, 892.096449"/>

<CrossSectPnt OE=" -4.000200, 892.091457"/>

<CrossSectPnt OE=" -4.000178, 892.027546"/>

<CrossSectPnt OE=" -4.249904, 892.028701"/>

</MaterialCrossSectEnvelop>


-<MaterialCrossSectEnvelop area="6.13134921968594E-03">

<CrossSectPnt OE=" -5.885287, 892.036261"/>

<CrossSectPnt OE=" -5.750200, 892.126319"/>

<CrossSectPnt OE=" -5.750060, 892.035636"/>

<CrossSectPnt OE=" -5.885287, 892.036261"/>

</MaterialCrossSectEnvelop>

</MaterialCrossSect>


-<MaterialCrossSect name="ATERRO - CALÇADA DIREITA" cumVolume="0" volume="0" area="5.41631406135821E-02">


-<MaterialCrossSectEnvelop area="0.028201527166857">

<CrossSectPnt OE=" 5.232389, 891.986101"/>

<CrossSectPnt OE=" 5.750000, 891.996453"/>

<CrossSectPnt OE=" 5.750200, 892.126319"/>

<CrossSectPnt OE=" 6.014144, 891.950347"/>

<CrossSectPnt OE=" 5.356544, 891.986190"/>

<CrossSectPnt OE=" 5.232389, 891.986101"/>

</MaterialCrossSectEnvelop>


-<MaterialCrossSectEnvelop area="2.59616134467251E-02">

<CrossSectPnt OE=" 4.000165, 891.990559"/>

<CrossSectPnt OE=" 4.000200, 892.091457"/>

<CrossSectPnt OE=" 4.249800, 892.096449"/>

<CrossSectPnt OE=" 4.249965, 891.989404"/>

<CrossSectPnt OE=" 4.000165, 891.990559"/>

</MaterialCrossSectEnvelop>

</MaterialCrossSect>

</MaterialCrossSects>

</CrossSect>

I have already managed to separate the values of Landfill in Lane|Left Sidewalk| Right Sidewalk, But for some reason I can not add the sidewalks, I would like to present in the table only track landfill and sidewalk landfill. Today it’s like this:

Hoje está assim:

My code is like this:

<xsl:for-each select="./MaterialCrossSects/MaterialCrossSect">

                    <xsl:variable name="Area" select="@area" />
                      <xsl:if test="@name='ATERRO - PISTA'">
                      <td align="left">
                        <xsl:value-of select="landUtils:FormatNumber(string($Area), string($SourceAreaUnit), string($Surface.2D_Area.unit), string($Surface.2D_Area.precision), string($Surface.2D_Area.rounding))" />
                      </td>
                        </xsl:if>
                        <xsl:if test="@name='ATERRO - CALÇADA ESQUERDA'">
                         <xsl:variable name="Teste1" select="@area" />
                      <td align="left">
                        <xsl:value-of select="landUtils:FormatNumber(string($Teste1), string($SourceAreaUnit), string($Surface.2D_Area.unit), string($Surface.2D_Area.precision), string($Surface.2D_Area.rounding))" />
                      </td>
                        </xsl:if>
                        <xsl:if test="@name='ATERRO - CALÇADA DIREITA'">
                         <xsl:variable name="Teste2" select="@area" />
                      <td align="left">
                        <xsl:value-of select="landUtils:FormatNumber(string($Teste2), string($SourceAreaUnit), string($Surface.2D_Area.unit), string($Surface.2D_Area.precision), string($Surface.2D_Area.rounding))" />
                      </td>
                        </xsl:if>
                          <xsl:value-of select="$Teste1+$Teste2" /> <!-- ERRO -->

                  </xsl:for-each>

When I create variables within ifs they only work within ifs they don’t work outside of them, I don’t understand why

1 answer

0

Hello, I think you should do implementing Choose-when as below (I’ve eliminated some of your functions, but it’s only readapt for your problem):

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

<xsl:template match="/">
    <xsl:for-each select="MaterialCrossSects">


        <xsl:if test="MaterialCrossSect[@name='ATERRO - PISTA']">
            <xsl:variable name="Area" select="MaterialCrossSect[@name='ATERRO - PISTA']/@area" />
            <td align="left">
                <xsl:value-of select="$Area" />
            </td>
        </xsl:if>
        <xsl:choose>
            <xsl:when test="MaterialCrossSect[@name='ATERRO - CALÇADA ESQUERDA'] and MaterialCrossSect[@name='ATERRO - CALÇADA DIREITA']">
                <td align="left">
                    <xsl:value-of select="MaterialCrossSect[@name='ATERRO - CALÇADA ESQUERDA']/@area + MaterialCrossSect[@name='ATERRO - CALÇADA DIREITA']/@area" />
                </td>
            </xsl:when>
            <xsl:when test="MaterialCrossSect[@name='ATERRO - CALÇADA ESQUERDA']">
                <td align="left">
                    <xsl:value-of select="MaterialCrossSect[@name='ATERRO - CALÇADA ESQUERDA']/@area" />
                </td>
            </xsl:when>
            <xsl:when test="MaterialCrossSect[@name='ATERRO - CALÇADA DIREITA']">
                <td align="left">
                    <xsl:value-of select="MaterialCrossSect[@name='ATERRO - CALÇADA DIREITA']/@area" />
                </td>
            </xsl:when>
        </xsl:choose>

    </xsl:for-each>
</xsl:template>

Browser other questions tagged

You are not signed in. Login or sign up in order to post.