?
Solved

XML - Looping through distinct node - URGENT REQUEST

Posted on 2005-03-18
1
Medium Priority
?
191 Views
Last Modified: 2008-03-17
Greetings,

I hope I can clearly explain what I am looking for.   In the ASP code below, you will see the statement "Set oNodes = oXML.selectNodes("//z:row[@WHSE='AK' and @FDATE<999901 and @FDATE>200403 ]")"   As you can see, I am selecting a specific Warehouse(WHSE) record and then running the remaining code against that record.  The code works fine...execept for the fact that I want to run the code for each distinct WHSE.   In my XML data file there will be multiple rows of data for each Warehouse locations.  I want to select each distinct one, run the calculations below and move on to the next distinct WHSE.   In the end, I will be incrementing a counter of locations that are in a negative variance and will render that value back to the HTML screen.

Thank you in advance for your help.   THIS IS A HOT REQUEST!  

ASP Server Side Code:

<%

' Declarations

    Dim myValue
    Dim mySalesSumHist
    Dim myCostSumHist    
    Dim mySalesSumCur
    Dim myGMCur
    Dim myCostSumCur
    Dim myVarianceCount

    mySalesSumHist = 0
    myCostSumHist = 0
    myGMHist = 0
    myVarianceCount = 0

    Set oXML = Server.CreateObject("MSXML2.DOMDocument")
    oXML.load("E:\sites\reports.xxx.com\GMVariance.xml")
    oXML.setProperty "SelectionNamespaces", "xmlns:x='#RowsetSchema'"
    Set oNodes = oXML.selectNodes("//z:row[@WHSE='AK' and @FDATE<999901 and @FDATE>200403 ]")
    Set vNodes = oXML.selectNodes("//z:row[@WHSE='AK' and @FDATE=999901]")

    If oNodes.length > 0 Then

        For Each oNode In oNodes
       
        SalesHist = oNode.selectSingleNode("@c3").text
        CostsHist = oNode.selectSingleNode("@c4").text
        mySalesSumHist = mySalesSumHist + SalesHist
        myCostSumHist = myCostSumHist + CostsHist
   
        Next
       
    End If
   

    If vNodes.length > 0 Then

        For Each vNode In vNodes
       
        SalesCur = vNode.selectSingleNode("@c3").text
        CostsCur = vNode.selectSingleNode("@c4").text
       
        mySalesSumCur = mySalesSumCur + SalesCur
        myCostSumCur = myCostSumCur + CostsCur
   
        Next
     
     End If  
   
   ' Do the math

     myGMHist = ((mySalesSumHist - myCostSumHist)/mySalesSumHist)*100
     myGMCur = ((mySalesSumCur - myCostSumCur)/mySalesSumCur)*100
     myGMVar = myGMCur - myGMHist

   ' Now update the variance counter if a WHSE exceeds limits

      If myGMVar < 0 then
      
            myVarianceCounter = myVarianceCounter + 1

      End if
     
   ' Now lets render the results of the counter back to the HTML screen  
     
     Response.write "<form name='myForm'>"
     Response.write "<input type='Text' id='myVarianceCounter' value='" & myVarianceCounter & "' />"
     Response.write "</form>"

%>
0
Comment
Question by:kdwood
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 26

Accepted Solution

by:
rdcpro earned 2000 total points
ID: 13576798
In XSLT this sort of thing is pretty easy, but you should be able to do it with DOM methods:

I think I'd do it by first iterating over all row nodes, and building a dictionary object (associative array) of unique values for WHSE. Actually it could be a simple one dimensional array of strings, with a bit of logic to see if a value exists before adding a new one.  Then iterate over the items and construct your nodesets.

Regards,
Mike Sharp
0

Featured Post

Congratulations! You’re Certified – Now What?

Starting a new career can be overwhelming. Becoming certified in your field of expertise is a great start, but where do you go from here?  Here are some tips to help you on your career journey.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses

770 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question