Click here to Skip to main content
15,886,689 members
Articles / Programming Languages / XSLT

Archival Retrieval Solution for ASP Using XML Data

Rate me:
Please Sign up or sign in to vote.
3.00/5 (1 vote)
9 Oct 2006CPOL 25.8K   155   12   1
Retrieving data from XML using column indexing.

Introduction

This archival retrieval solution is appropriate for applications that do not use any database, but an XML data source. When it comes to speed, I can say that XSLT is the best in terms of data crunching. In this article, I describe how this retrieval solution works using ASP and calls an XSLT program that accesses an XML file. This is a simple prototype that gives you an idea of how XSLT gets interfaced with an ASP application.

Using the Code

Just add or copy the source code file into the wwwroot folder (IIS root folder). Then you can access the file by calling it from the browser.

  1. Add search.asp to the created folder for the archiver. This contains the ASP code that allows the entry of queries.
  2. VBScript
    ' Source file '
    xslFile = "general.xsl"
    xmlFile = "test.xml"
    
    Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")
    xslDoc.async = false
    
    xslDoc.load(Server.MapPath(xslFile))
    
    Set xmlDoc = Server.CreateObject("MSXML2.DOMDocument")
    xmlDoc.async = false
    xmlDoc.load(Server.MapPath(xmlFile))
    
    'This is the critical widget, a compliled XSL template'
    Set myTemplate = Server.CreateObject("MSXML2.XSLTemplate")
    myTemplate.stylesheet = xslDoc
    
    Set myProc = myTemplate.createProcessor
    myProc.input = xmlDoc
    
    myProc.transform
    Response.Write(myProc.output)
  3. Add general.xsl as the query statement on the XML file.
  4. XML
    <xsl:for-each select="//HAWB[@HawbNo=$p_hawb]">
     <tr>
    <td><xsl:value-of select="IDNO"/></td>      
        <td><xsl:value-of select="SHIPDATE"/></td>
     <td><xsl:value-of select="DECLNO"/></td>
        <td><xsl:value-of select="CONSCOM"/></td>
        <td><xsl:value-of select="SHIPCOM"/></td>
     </tr>
    </xsl:for-each> 
  5. Add test.xml as the test data formatted in XML.
  6. XML
    <?xml version="1.0" encoding="ISO-8859-1" ?>
    <DATALOG>
     <HAWB HawbNo="815710000000">
       <IDNO>AA000003285001</IDNO>
       <DECLNO>182106240</DECLNO>
       <SHIPDATE>1/1/1998</SHIPDATE>
       <CONSCOM>CONSIGNEE COMPANY 1 Inc </CONSCOM>
       <SHIPCOM>SHIPPER COMPANY 1 Inc</SHIPCOM>
     </HAWB>
     <HAWB HawbNo="815710000001">
       <IDNO>AA000003285002</IDNO>
       <DECLNO>182106241</DECLNO>
       <SHIPDATE>1/1/1998</SHIPDATE>
       <CONSCOM>CONSIGNEE COMPANY 2 Inc </CONSCOM>
       <SHIPCOM>SHIPPER COMPANY 2 Inc</SHIPCOM>
     </HAWB>
     <HAWB HawbNo="815710000002">
       <IDNO>AA000003285003</IDNO>
       <DECLNO>182106242</DECLNO>
       <SHIPDATE>1/1/1998</SHIPDATE>
       <CONSCOM>CONSIGNEE COMPANY 3 Inc </CONSCOM>
       <SHIPCOM>SHIPPER COMPANY 3 Inc</SHIPCOM>
     </HAWB>
    </DATALOG>

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Hong Kong Hong Kong
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSource code missing Pin
cornejoserrano20-Nov-06 12:28
cornejoserrano20-Nov-06 12:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.