·  XSLT – Introduction – Principle

 

- Comments on text.xml

  - Plain text is called text element. It is element that differs from all other since it doesn't have tag.

  - test.xml has following elements: <people>, List of students, <student>, <name>, Jack, <age>, 23

  - <people> element is called root element since it is the first one.

  - Since <student> element is placed inside <people> element it is said that:

    - <student> is child of <people>

    - <people> is parent of  <student>

    - Value of text element is it's string with.

    - Value of all other element's is string with values of all of it's text subelements.

 

- Comments on text.xsl

  - XSLT goes through nodes of test.xml begining from the root element <people>.

  - When XSLT gets to a node which matches some of the defined templates it executes that template.

  - If no such template can be found SLT executes default template which is defined as follows:

    - when you apply template to an element, process its child elements

    - when you apply template to a text node, return its value

  - This info was taken from http://www.dpawson.co.uk/xsl/sect2/defaultrule.html

 

- Comments on result

  - Since no template is defined for <people> default one is used which starts taking children.

  - First child is text element. There is also no template defined for it so default one is taken which simply returns the text.

  - For the next element, <student>, we have defined template which simply returns string "Found student".

  - Children on <student> are skiped since we haven't defined any operations on them in our template.

 

    test.xml

    <?xml version="1.0"?>

    <?xml-stylesheet type="text/xsl" href="test.xsl"?>

    

    <people>

    

      List of students

      <student>

        <name>Jack</name>

        <age> 23  </age>

      </student>

    

    </people>

    

    test.xsl

    <?xml version="1.0" ?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    

      <xsl:template match="student">

        Found student

      </xsl:template>

    

    </xsl:stylesheet>

    

    result

    List of students Found student