Skip to main content

Applying a Style Sheet to an XML Document

A style sheet object that passes into the transformNode method needs to be recompiled every time the method is called. Compiling a style sheet means setting all its template rules in an executable state. By using the XSLTemplate object and the XSLProcessor object to perform transformation facilitates  the reduction of overheads and increases the performance of an XSLT application.

The XSLTemplate Object


The XSLTemplate object is a dom object that is used to access an XSLT style sheet. This object is used to hold a cached style sheet that can then be dynamically associated with an XML document.

Before a style document can be applied to an XML document, it is converted into a tree structure by the parser. In the early versions of MSXML, the style sheet had to be compiled each time it was required for processing an XML document. In other words, the tree structure for a style sheet had to be recreated for the use of XSL document, as the compiled version was not stored in the system. This resulted in a longer processing time. However, in MSXML 2.6 and later, a compiled version of the XSLT document is stored in the cache memeory of the computer. This means that the XSLT tree is created the first time the document is compiled. For each successive use of the style sheet, the compiled version is reused.

The XSLT tree structure is loaded into the memory of the computer and used to process the XML document. This is because the XSLTemplate object stores the compiled XSLT document. Therefore, you must first create an XSLTemplate object. In the following example, an XSLTemplate object called xsltobj is created using JavaScript:

           xsltobj= new ActiveXObject ("MSXML2.XSLTemplate . 6 . 0") ;

This object must be associated with an XSLT style sheet document. Consider the following code snippet:

          var xsldocobj= new  ActiveXObject ("Msxm12.freeThreadedDOMDocument . 6 . 0") ;
           xsldocobj . load ("products . xsl") ;
           xsltobj . stylesheet=xsldocobj ;

In the preceding example, an instance of the FreeThreaded DOMDocument object is created. This object can be used to access an XML document as well as an XSLT style sheet. This is because XSLT is an application of XML. The load () method of the FreeThreaded DOMDocument object is used to associate the XSL document products.xsl with the xsldocobj object. The stylesheet property of the xsltobj object is then used to associate the XSLTemplate object with the object that holds the XSL document.

The XSLProcessor Object


To process an XML document by using a style sheet, you must create an instance of the XSLProcessor object. This object is used to apply a style sheet to an XML document and then process that document. The XSLProcessor object is supported only in IE 5.0 and higher versions.

The XSLProcessor object applies the given XSLT document to a specifc XML document. In other words, this object transforms an XML document by using the XSLT style sheet. For example, an XML document can be transformed into an HTML document by applying the appropriate XSLT style sheet by using XSLProcessor object.

The JavaScript code to create an XSLProcessor object is as follows:

        var  xsalprocobj= xsltobj.createProcessor ( ) ;

In this example, the createProcessor ( ) method is used to create a new XSLProcessor object called xslprocobj. The createProcessor ( ) method is called by xsltobj, which represents a cached version of a compiled XSLT template. The xsltobj object is associated with a specific style sheet contained in the variable xsldocobj.

You can then create the XML document for which the style sheet contained in the xsltobj object must be applied. Consider the following example:

        var xmldocobj = new ActiveXObject ("Msxm12 . DOMDocument . 6 . 0") ;
        xmldocobj . load ("products . xml") ;

In the example, a new DOMDocument object called xmldocobj is created. The load ( ) method of this object is used to associate an XML document called products . xml with this object. This XML document is then passed to the XSLProcessor object as an input by using the input property. This property is used to specify the XML tree that must be transformed, as follows:

        xslprocobj . input=xmldocobj ;

The transform ( ) method of the XSLProcessor object is then invoked. This method performs the transformation of an XML document. During transformation, the tree structures of the XML and XSLT documents are used as input. The XSLT tree is applied to the XML tree and the document is then processed. The output of this process is an XML document that is rendered in the manner specified in the XSLT document. Consider the following example:

       xslprocobj . transform ( ) ;

In the preceding example, the transform ( ) method of the XSLProcessor object is invoked. The transform() method can be called multiple times for an XML Document to transform the different sections of the XML document.. The result of the transform ( ) method is displayed using the output property of the XSLProcessor object. The output can be displayed in a browser window or a message box. Consider the following example:

      alert (xslprocobj . output ) ;

In this example, the alert ( ) method is used to display the data stored in the transformed XML document in a message box.

Comments

Popular posts from this blog

difference between structure and union in C Language

In c language article we will see the difference between union and structure. Both are the user define datatype in c language. See the table which is mentioned below: ASP.NET Video Tutorial Series Structure Union1.The keywordstruct is used to define a structure 1. The keyword union is used to define a union. 2. When a variable is associated with a structure, the compiler allocates the memory for each member. The size of structure is greater than or equal to the sum ofsizes of its members. The smaller members may end with unused slack bytes. 2. When a variable is associated with a union, thecompiler allocates thememory by considering the size of the largest memory. So, size of union is equal to the size of largest member. 3. Each member within a structure is assigned unique storage area of location. 3. Memory allocated is shared by individual members of union. 4. The address of each member will be in ascending order This indicates that memory for each member will start at different offset v…

Difference between Linear search and Binary Search in c language

SQL Video Channel : Download all SQL Video



Binary Search Linear Search Works only on sorted items. such as  1,2,3,4,5,6  etc
Works on sorted as well as unsorted items. 12,4,5,3,2,1 etc Very efficient if the items are sorted Very efficient if the items are less and present in the beginning of the list. such as Suppose your list items are : 12,3,4,5,1 and you want to search 12 number then you get beginning in the list. Works well with arrays and not on linked lists. Works with arrays and linked lists.
Number of comparisons are less More number of comparisons are required if the items are present in the later part of the array or its elements are more.

Memory representation of Linked List Data Structures in C Language

Memory representation of Linked List

             In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.

               Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:


      Suppose next node is allocated at an address 506, so the list becomes,



  Suppose next node is allocated with an address with an address 10,s the list become,


The other way to represent the linked list is as shown below:




 In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of next node. The last node …