Monday, February 8, 2010

XSLT and XPATH

What is XSLT?

XSLT stands for XSL Transformations and is a language used to transform XML documents into XHTML documents or to other XML documents.

What are the roles of XSLT?

The roles of XSLT are:

XSLT is used to transform an XML document into another XML document such as HTML, etc.
XSLT can be used to add or remove elements and attributes to or from the output file.
XSLT can also be used for rearranging and sorting elements.
It can also be used for performing tests and making decisions about hiding and displaying of elements
.

XSLT and XPATH-

What is XSLT? Explain its relationships with XSL.

XSLT stands for eXtensible Stylesheet Language Transformations. It is a language used to convert XML documents to XHTML or other XML documents. This conversion is done by transforming each XML element into an (X)HTML element.. it uses XPath to find information in a XML document. XSLT is nothing but transforming XSL’s. Xpath defines the parts of the source document that must match one or more predefined templates. Once a match is found, XSLT will transform the match into the result document.

What is XSLT stylesheet?

XSL stylesheet is just like a XML document used as a program text or a source. It contains sets of rules and instructions used for transformations. XSLT stylesheet along with the XML source documents are the inputs to the XSLT processor. The template rule contains two parts: a pattern used to match the nodes in the source document and a template which can be instantiated to form part of the result tree. A stylesheet is represented by an xsl:stylesheet element in an XML document.

Discuss the role of XPATH.

XPATH is used to scan the XML document for navigation of elements and attributes. It contains a library of standard functions string ad numeric values. For navigation, XPATH makes use of path expressions to select nodes or sets of nodes in a XML document.

Explain the XSLT data model.

XSLT shares the same data model of XPATH with some additions. XSLT accepts a XSLT stylesheet as an input and output is another XML, text or another document. The model is based on text nodes. These text nodes are embedded within element nodes. The model is a hierarchical structure like a tree. The tree has a variety of nodes like- text nodes, attribute nodes, element nodes, comment nodes, and processing instruction nodes. For every node type there is a way of determining a string-value for a node of that type.

Why the need for XHTML?

If a script in an HTML document is not well formed, small devices like mobile phones fail to display the content properly. Also, upgrading all the browsers to support XML is a timely affair. An intermediate solution is XHTML that is a combination of HTML and XML. In XTML the content has to be well formed so that there is no bad HTML.

XHTML vs HTML

XHTML
Elements must be properly nested
Elements must be closed
Elements must be in lowercase
Documents must have one root element

HTML
Elements need not be properly nested
Elements need not be always closed
Elements need not be in lowercase
Documents need not have one root element

Explain the XHTML syntax rules.

Some Syntax rules that need to be followed with XHTML are:

That Attribute names must be in lower case, their values must be in quotes and their minimization is done away from usage.

Also the ‘name’ attribute has been replaced by the ‘id’ attribute. The XHTML DTD defines mandatory elements.

What is the XMLHttpRequest Object?

The XMLHttpRequest object is used to connect to the server through http. Scripts use it to do so programmatically.

The EventTarget interface needs to be implemented if an object implements the XMLHttpRequest interface. Also, an XMLHttpRequest() constructor needs to be provided by objects that implement the Window interface.

Explain common XMLHttpRequest Object Properties. i.e. onreadystatechange, readyState, responseText, responseXML, status, statusText.

  • The ‘onreadystatechange’ property fires at every state change event.
  • The ‘readyState’ property is an object status integer. It uses the integers 0 to 4 for uninitialized, loading, loaded, interactive and complete states.
  • The ‘responseText’ property is a string version of data returned from server process.
  • The ‘responseXML’ property is DOM-compatible document object of data returned from server process.
  • The ‘status’ property is for returning numeric codes from the server like error codes, etc.
  • The ‘statusText’ property is used for string messages that accompany the status code.

Explain common XMLHttpRequest Object Methods.

  • The abort() is used to stop the current request.
  • The getAllResponseHeaders() method is used to return the full set of headers as a string.
  • The getResponseHeader("headerLabel") method is used to return the string value of a single header label.
  • The open("method", "URL"[, asyncFlag[, "userName"[, "password"]]]) is used to assign the destination URL, method, and other optional attributes of a request.
  • The send(content) method transmits the request, optionally with postable string or the data of DOM object.
  • The setRequestHeader("label", "value") method is used to assign a label/value pair to the header to be sent with a request.

No comments:

Post a Comment