BizTalk Utilities CV ,   Jobs ,   Code library  
 
 
          

Page 2 of 4

Creating the XML objects in ASP

To view the full ASP code used, click here

The first thing that ASP needs to do is create some server side objects which are capable of containing an XML document. The object type is "microsoft.xmldom" and is created with

set objXML=Server.CreateObject("microsoft.xmldom")

To construct my page, I need to create four XML objects.

  • objMainXML - contains the details of every demo as held in example.xml
  • objXML - contains the XML of the demo chosen
  • objXSL - contains the XSL stylesheet to be applied
  • objDefaultXSL - contains the default stylesheet that IE5 uses to display XML

The next step is to find out what demo is to be displayed and which XSL to use. This is controlled by the parameters passed in the Querystring.

The parameters are:

  • id - contains the id number of the demo to be used
  • xsl - contains the id of the xsl stylesheet to be used
  • xml - flag to indicate whether or not to display the xml

e.g.

The URL http://www.TopXML.com/xsl/articles/scripting/examples.asp?id=2&xsl=1 will show the effects of the 1st stylesheet on the 2nd demo and show the code for the 1st stylesheet.

The URL http://www.TopXML.com/xsl/articles/scripting/examples.asp?id=2&xsl=2 will show the effects of the 2nd stylesheet on the 2nd demo and show the code for the 2nd stylesheet.

while the URL http://www.TopXML.com/xsl/articles/scripting/examples.asp?id=2&xsl=1&xml=1 will show the effects of the 1st stylesheet on the 2nd demo but will show the code for the XML instead.

The parameters are accessed by:

exampleID=Request.QueryString("id")
XSLid=Request.QueryString("xsl")

Now that we've found out which demo and XSL is to be used we can load the examples.xml file which contains the details of all of the demos.

'Set async=False to prevent the code from continuing before the xml is fully loaded
objMainXML.async=False
objMainXML.load(server.MapPath("examples.xml"))

The object objMainXML now contains the XML file as seen on the previous page

To find the demo that is being used we need to match up the exampleID given in the querystring with the id attribute given in the XML, which is contained in objMainXML

This sets objExamples to the root node of objMainXML
set objExamples=objMainXML.documentElement

This sets Demo to the example whose attribute id is equal to the variable exampleID
set Demo=objExamples.selectSingleNode("example[@id=" &exampleID &"]")

Demo now contains all the details of the chosen example. If id=2 then the Demo object would contain the XML as seen on the previous page.
The node <xmlFile> contains the name of the XML file to use.
To access this use:

XMLFile=demo.selectSingleNode("xmlFile").text

Now we need to create links for each XSL example and to display the explanation associated with the chosen example. First we need to create an object that contains all the XSL examples.

set XSLexamples =demo.selectSingleNode("XSLexample")

Note the difference between setting the variables XMLFile and XSLexamples.
XMLFile is a variable that contains the text of the node <xmlFile> while
XSLexamples is an XML object that contains the node <XSLexample> and all its children.

Now that we know what XSL stylesheet we're going to apply to which XML we can start to build some HTML as shown on page 3

          

Page 2 of 4

 

Recent Jobs

A great opportunity to Digital Vide
here is a greate opportunity as a S
A great opportunity as a Network En
A Greate Opportunituy as a SQL Deve
An immediate job opportunity as a B

View all Jobs (Add yours)
View all CV (Add yours)



Information Online

swimming pool contractor
chicago web site design
United Kingdom Conference Calling
Web Hosting
online fax
designer sunglasses
answering service


    Email TopXML  

Front Page Daily Stuff TopXML Forum XML blogs XML Newsgroups BizTalk Biztalk Utilities Biztalk Utilities Tutorial B2B SAP XML Microsoft .NET Dotnet System XML Soapformatter SQLXML XMLserializer XQuery PHP PHP SimpleXML PHP XML Dom PHP XML RPC PHP XSLT Java Java Java XML Xalan Microsoft ASP ASP Schemas XML SQL Server XML XMLDom XSL XSL Tutorial XSLT Stylesheets General Javascript CSS XHTML WAP