locked
Doing Math in XML Embedded Expression RRS feed

  • Question

  • Hello all.  I'm getting stumped by what I hope is a simple problem.  I'm trying to embed a simple formula incrementing a variable to act as a "line number" for an XML document.  Writingliteral XML in visual basic.  Here's what the code looks like:

                                               <%= From d In orderData
                                               Select <ItemOut quantity=<%= d.OrderQuantity %> lineNumber=<%= i %>>
                                                          <ItemID>
                                                              <SupplierPartID><%= d.VendorPartNo %></SupplierPartID>
                                                          </ItemID>
                                                          <ItemDetail>
                                                              <UnitPrice>
                                                                  <Money currency="USD"><%= d.PricePerPackage %></Money>
                                                              </UnitPrice>
                                                              <Description xml:lang="en"><%= d.Description %></Description>
                                                              <UnitOfMeasure><%= d.OrderUOM %></UnitOfMeasure>
                                                          </ItemDetail>
                                                          <%= i = i + 1 %>
                                                      </ItemOut>
                                               %>

    I was expecting each iteration of d in OrderData to tick i + 1, however, it is simply returning "false".  See the output XML here:

    <ItemOut quantity="1" lineNumber="1">
            <ItemID>
              <SupplierPartID>99999</SupplierPartID>
            </ItemID>
            <ItemDetail>
              <UnitPrice>
                <Money currency="USD">0.00</Money>
              </UnitPrice>
              <Description xml:lang="en">Tub and Tile Caulk Biscuit</Description>
              <UnitOfMeasure>cs</UnitOfMeasure>
            </ItemDetail>false</ItemOut>
          <ItemOut quantity="1" lineNumber="1">
            <ItemID>
              <SupplierPartID>999999</SupplierPartID>
            </ItemID>
            <ItemDetail>
              <UnitPrice>
                <Money currency="USD">0.00</Money>
              </UnitPrice>
              <Description xml:lang="en">Tub and Tile Caulk Almond</Description>
              <UnitOfMeasure>cs</UnitOfMeasure>
            </ItemDetail>false</ItemOut>


    • Edited by StefanVon Monday, February 9, 2015 1:47 PM
    Monday, February 9, 2015 1:46 PM

Answers

  • The answer was given here

    Thank you to Viorel_

    • Marked as answer by StefanVon Tuesday, February 10, 2015 4:22 PM
    Tuesday, February 10, 2015 4:22 PM

All replies

  • I tried making a call to a function instead, where the function did the incrementing and returned the integer, but that is returning "False" as well.

                                               <%= From d In orderData
                                               Select <ItemOut quantity=<%= d.OrderQuantity %> lineNumber=<%= incrementI(i) %>>
                                                          <ItemID>
                                                              <SupplierPartID><%= d.VendorPartNo %></SupplierPartID>
                                                          </ItemID>
                                                          <ItemDetail>
                                                              <UnitPrice>
                                                                  <Money currency="USD"><%= d.PricePerPackage %></Money>
                                                              </UnitPrice>
                                                              <Description xml:lang="en"><%= d.Description %></Description>
                                                              <UnitOfMeasure><%= d.OrderUOM %></UnitOfMeasure>
                                                          </ItemDetail>
                                                      </ItemOut>
                                               %>

    Resulting XML:


    Still stumped as to what is going on here

          <ItemOut quantity="1" lineNumber="false">
            <ItemID>
              <SupplierPartID>999999</SupplierPartID>
            </ItemID>
            <ItemDetail>
              <UnitPrice>
                <Money currency="USD">0.00</Money>
              </UnitPrice>
              <Description xml:lang="en">Tub and Tile Caulk Biscuit</Description>
              <UnitOfMeasure>cs</UnitOfMeasure>
            </ItemDetail>
          </ItemOut>
          <ItemOut quantity="1" lineNumber="false">
            <ItemID>
              <SupplierPartID>999999</SupplierPartID>
            </ItemID>
            <ItemDetail>
              <UnitPrice>
                <Money currency="USD">0.00</Money>
              </UnitPrice>
              <Description xml:lang="en">Tub and Tile Caulk Almond</Description>
              <UnitOfMeasure>cs</UnitOfMeasure>
            </ItemDetail>
          </ItemOut>


    • Edited by StefanVon Monday, February 9, 2015 7:41 PM
    Monday, February 9, 2015 7:40 PM
  • The answer was given here

    Thank you to Viorel_

    • Marked as answer by StefanVon Tuesday, February 10, 2015 4:22 PM
    Tuesday, February 10, 2015 4:22 PM