XML XSL Question about varibles

Discussion in 'Programming' started by mfawn, Apr 21, 2009.

  1. #1
    I'm not really an XML developer but I have been asked to update an XSL sheet.

    I have the following code and I'm trying to change it so I don't have to use a for-each loop because I'm losing the variable due to scope. I need to create a grand total so I need to total up 3 different elements but when I try to total this section it won't work because its out of scope when the loop closes.

    The XML file element that needs to be pulled is always the 2nd element and has an element_id of LABOUR. Can I call it without using the loop or can I make the variable global so it doesn't lose scope?

    <route_cost_elements>
    <element_id>MATERIAL</element_id>
    <element_pc>99.9</element_pc>
    <element_cost_mr>333.33</element_cost_mr>
    <element_price_mr>444.44</element_price_mr>
    <element_cost_run>55.55</element_cost_run>
    <element_price_run>77.77</element_price_run>
    </route_cost_elements>

    <route_cost_elements>
    <element_id>LABOUR</element_id>
    <element_pc>11.22</element_pc>
    <element_cost_mr>22.33</element_cost_mr>
    <element_price_mr>44.55</element_price_mr>
    <element_cost_run>55.66</element_cost_run>
    <element_price_run>88.99</element_price_run>
    </route_cost_elements>


    Here is part of the XSL file:

    <xsl:for-each select="route_detail/route_cost_elements">
    <xsl:if test="position() =2">
    <xsl:variable name="totallabour" select="element_cost_mr + element_cost_run"/>
    </xsl:if>
    </xsl:for-each>
     
    mfawn, Apr 21, 2009 IP