Need help selecting childeren Nodes in ASP

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tfhanson
    New Member
    • Jun 2007
    • 3

    Need help selecting childeren Nodes in ASP

    Hi, been a real long time since I have worked in ASP and XML and a neighbor asked me to help him with a web page. I have an XML file that I am trying to search thru and display the children nodes......

    Here is a sample of the xml
    Code:
    <document>
       <MEMBER>
    		<ID>000-00-0010</ID>
    			<CHARGES>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>BANQ</Code><Desc>BANQUET</Desc> <Amount>0.00</Amount><Note></Note></CHARGE>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>OSR</Code><Desc>RENT</Desc><Amount>0.00</Amount> <Note></Note></CHARGE>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>PR</Code><Desc>POSTAGE REIMBUR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>YBS</Code><Desc>YRBK SPONSOR</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>ZA</Code><Desc>ADMIN.FEE</Desc> <Amount>0.00</Amount><Note></Note></CHARGE>
    			</CHARGES>
    			<PAYMENT>
    				<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
    			</PAYMENT>
    	</MEMBER>
    	<MEMBER>
    		<ID>000-00-0011</ID>
    			<CHARGES>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>PC</Code><Desc>SICK COMPER CAP</Desc><Amount>558.00</Amount><Note>10/31/2004</Note></CHARGE>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate> <Code>ZA</Code><Desc>ADMIN.FEE</Desc><Amount>16.74</Amount> <Note></Note></CHARGE>
    			</CHARGES>
    			<PAYMENT>
    				<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
    			</PAYMENT>
    	</MEMBER>
    	<MEMBER>
    		<ID>000-00-0012</ID>
    			<CHARGES>
    				<CHARGE><ChargeDate>06/25/2007</ChargeDate><Code>ZA</Code> <Desc>ADMIN.FEE</Desc><Amount>0.00</Amount><Note></Note></CHARGE>
    			</CHARGES>
    			<PAYMENT>
    				<PaymentDate></PaymentDate><PaymentAmount>0.00</PaymentAmount>
    			</PAYMENT>
    	</MEMBER>
    </document>
    I have put together this XLS file

    Code:
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
    	<xsl:template match="/">
    		<h1>Charges</h1>
    		<table cellpadding="3" cellspacing="0">
    			<tr>
    				<th>Charge Date</th>
    				<th>Charge Code</th>
    				<th>Description</th>
    				<th>Amount</th>
    				<th>Note</th>
    			</tr>
    			<xsl:apply-templates select="//CHARGE"/>
    		</table>
    	</xsl:template>
    	<xsl:template match="CHARGE">
    		<tr>
    			<td><xsl:value-of select="ChargeDate" /></td>
    			<td><xsl:value-of select="Code" /></td>
    			<td><xsl:value-of select="Desc" /></td>
    			<td><xsl:value-of select="Amount" /></td>
    			<td><xsl:value-of select="Note" /></td>
    		</tr>
    	</xsl:template>
    </xsl:stylesheet>
    What I am trying to do is display the charges for say ID = 000-00-0010

    Here is the VB script I am trying to use.....

    Code:
    function transformDetailXML( XML, XSL, strDetail ) 
    	Dim objXML
    	Dim objXSL
    	Dim objNode
    	'dim objCharges
    		  
    	Set objXML = getXMLDoc(XML)
    	Set objNode = objXML.SelectSingleNode("document/MEMBER/ID/[text()='" & strDetail & "']")
    	'Set objCharges = objNode.selectNodes("/CHARGES[CHARGE]")
    	
    	Set objXSL = getXMLDoc(XSL)		
    	If objXML.parseError <> 0 Then Response.Write reportParseError(objXML.parseError)
    	If objXSL.parseError <> 0 Then Response.Write reportParseError(objXSL.parseError)
    
    	transformDetailXML = objNode.transformNode(objXSL)
    End Function
    And lastly, this is what is showing in my browser....

    Searching Mode
    <ID>000-00-0010</ID>

    Thanks in advance for your help.....
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hello, tfhanson!

    I would like to get as much information from you as possible so when I move this thread you get what you need quicker. I think we need to make sure of some things first

    Can you tell me if you you know whether the XSL appropriately communicate with the XML file?

    You will need to get that working first so if you have a problem you'll know where it is coming from.

    Also, it might be helpful to you to indent your code in such a way to make it easier to read.

    I will try your code in HTML to see what it does...

    Comment

    • tfhanson
      New Member
      • Jun 2007
      • 3

      #3
      Yes, when I use the xml and xls files to show everything, it works fine... What I need to do is only show the charges for a particular Member.

      Comment

      • tfhanson
        New Member
        • Jun 2007
        • 3

        #4
        Thanks for looking, I solved it with straight vbscript, although I would still like to know how to do it with XLS

        Here is what solved it for me....



        xmlDoc = "exporting. xml"

        strDetail = "000-00-0010"

        Set objXML = getXMLDoc(xmlDo c)
        Set objNodeList = objXML.getEleme ntsByTagName("d ocument/MEMBER[ID='" & strDetail & "']/CHARGES/CHARGE")

        numberofitems = objNodeList.len gth

        For i = 0 To numberofitems - 1

        Set objHdl = objNodeList.ite m(i)
        Response.Write objHdl.childNod es(0).text & " " & objHdl.childNod es(1).text & " " & objHdl.childNod es(2).text & " " & objHdl.childNod es(3).text & " " & objHdl.childNod es(4).text & "<br>"

        Next

        Comment

        • paragguptaiiita
          New Member
          • Feb 2008
          • 21

          #5
          ctually i have a large XML file and i also made a XSL file for viewing that XML file on the web browser.When we view that XML file in web browser and edit that file then i want to update that XML file also.(here we can use any scripting language for updating )

          i don't know how it will, i saw this link Check this

          In this ASP is used for updating the XML file.I want the same thing but the problem is here the XML file is very small and file that i have is so large in which each node contains 3-4 attributes and 3-4 child also and each child also contains 3-4 attribute,this same thing is repeated many times in the file.

          Can u give me ur mail id so i can send my XML file and XSL file

          Comment

          Working...