x

XML – XSLT

PREV

XML XSLT:


  1. Transformation is a process of taking an XML document and turning it into a document in another form
  2. The process of applying rules to the source document is called transformation
  3. XSLT is a declarative language
  4. Programmer has control over the general course of transformation but not on the step-by-step processing of the XSLT processor
  5. XSLT stylesheet consists of a series of templates
  6. A template consists of an expression describing the form of some XML fragment and one or more elements specifying what output to generate when the form is matched in the source document.
  7. Each stylesheet contains a template that matches the root of a document – root template. The XSLT processor begins from this template
  8. XSLT works its way through the structures in the source document and the context is the node of the parse tree on which the processor if focussing
  9. An XSLT processor will start from the document element (root node in the tree) but the context changes throughout the course of processing
  10. Node tests: comment(), text(), node(), processing-instruction()
  11. XSLT has 37 elements and attributes
  12. Commonly used elements are categorized as
    1. Building stylesheets
    2. Controlling transformation output
    3. Generating simple output
    4. Generating XML
    5. Iteration
    6. Conditional tests
    7. Programming constructs
    8. Modularity
  13. Building stylesheets:
    1. or : This is the top-most element. This element must have two attributes: namespace and version
    2. : This element has four optional attributes – match, mode, priority, name.
    3. : Two child elements of this element are – and . If this element is used with no attributes, it tells the processor to match the templates in the stylesheet against the current context node.
  14. Controlling transformation output
    1. attribute is – “elements”
    2. attribute is – “elements”
    3. This element has 10 optional attributes – method, version, encoding, standalone, indent, omit-xml-declaration, doctype-public, doctype-system, media-type, cdata-section-elements is an empty element and is the child of the parent element –
  15. Generating simple output:
    1. element. This element has an attribute – “select” (required attribute). Value of the “select” attribute is an XPath expression. If the expression returns a collection of nodes, only first node is returned to the output.
    2. Making copies: and elements. element copies the current context node to the output. It does not bring along any attributes or child nodes. element copies current context node and all the nodes under it.
  16. Generating XML constructs directly: Five elements for creating major constructs of XML are:
  17. Iteration: element. This element operates on a collection of nodes designated by the value of its “select” attribute. While the element is executed, the nodes in the collection become the current context node.
  18. Conditional tests: element. This element does not have any “else” part. This element takes one attribute – “test” which is an XPAth expression element. This element has two child elements: and has no attributes. is the default part of the choose statement.
  19. Programming constructs:
    1. Declaring Variables: element This element has one required attribute – “name” It has one optional attribute – “select” (value of this attribute is an XPath expression) An XSLT variable cannot have its value changed (XSLT is free of sede-effects) Variables can be local or global
    2. Calling templates: A named template uses element to declare parameters and optionally give them the default values It is not an error to call a template without the required parameters, although processing may be affected Parameters can be local or global Templates can be called from orelements
  20. Modularity: and elements These elements have one required attribute: “href” Both are child elements of Both are empty elements Stylesheet included by has same priority as native template Templates imported by have lower priority To apply both native and imported templates, use statement
  21. Some things that CSS cannot do:
    1. CSS cannot do computations
    2. CSS cannot change the order of elements
    3. CSS cannot combine multiple documents
  22. XSLT
    1. XSLT stylesheet should be an XML document
    2. XSLT is based on pattern-matching
    3. XSLT is free of side effects
    4. XSLT uses iteration and recursion instead of loops
  23. Scenarios where XSLT is preferable:
    1. Information is to be rendered on different devices (web, handheld-devices etc)
    2. To exchange data between different partners who use different database systems
    3. When redesign of the site (say) is done very frequently
    4. To combine documents that are in different formats
  24. XSLT stylesheets use namespace prefixes to process the XML elements they contain. Anything that doesnt use the xsl namespace prefix is not processed, its written to the result tree.
  25. DOM, XSLT and XPath all use tree structures to represent data from an XML document.
  26. Stylesheet is itself an XML document
  27. The nodes to be processed are represented by context. Initially the context is the root of the XML document but it changes throughout the stylesheet
  28. Process of transformation is:
    1. XSLT stylesheet is parsed and converted into a tree structure
    2. XML document is parsed and converted into a tree structure
    3. XSLT processor is now at the root of the XML document
    4. matches the document root
    5. Process begins inside xsl:template where the element is matched with the value of “match” attribute
  29. Built-in templates have lower priority than any other templates.
  30. Following are built-in templates:
    1. for element and root nodes –
    2. for modes –
    3. for text and attribute nodes –
    4. for comment and processing-instruction nodes – This does not do anything
    5. for namespace nodes – This does not do anything.
  31. Top level elements – elements whose parent is element
    1. and
    2. and
    3. Other elements are: , and
  32. can appear only at the beginning of a stylesheet, while can appear anywhere
  33. XSLT uses XPath expression in the “match” and “select” attributes
  34. XPath works with parsed version of the XML document, means all the entities are resolved first.
  35. XSLT processor handles all elements before it does anything and then it processes element
  36. Attributes of element are:
    1. Select
    2. Data-type : It can be text, number or QName
    3. Order : It can be ascending, descending
    4. Case-order : It can be upper-first, lower-first. This attribute is used only when data-type=”text”
    5. lang
  37. element can be used within or elements.

PREV



Like it? Please Spread the word!

Post Your Thoughts