Presentation is loading. Please wait.

Presentation is loading. Please wait.

Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined.

Similar presentations


Presentation on theme: "Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined."— Presentation transcript:

1 Advanced XSLT II

2 Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined by an XPath expression we use a for-each element to control the iteration

3 Applies processing to all nodes in a given node set select attribute contains XPath expression defining the node set the current node changes at each iteration of for-each –changes the context for transforms of content

4 example we have XML data for a tutorial, divided into sections we wish to produce a numbered contents list in HTML we use for-each twice to create a numbered heading and a list of sections we use the position() function for the numbering

5 XML Tutorial XML and DTDs XPath and XSLT XSLT Tutorial XML and XSLT The Data

6 Section 1. XML Tutorial 1. XML and DTDs 2. XPath and XSLT Section 2. XSLT Tutorial 1. title>XML and XSLT … and so on for each section The Desired Output

7 Section..

8 Section.. </xsl:template

9 example - notes for-each select=section selects all section nodes in the current tutorial –position() will number the sections in document order for-each select=panel selects all panel nodes in the current section this is just a nested loop!

10 modes Sometimes you may wish to transform the same node in more than one way The transform for a node is defined in a template A mode attribute is available for template and apply-templates elements This allows more than one template to be defined for any node

11 example XML data for a famous scientists website The data contains a name element for each person featured on the site. We use mode to achieve two different presentations of name –table of contents –personal data entry

12 Alan Turing computer scientist mathematician cryptographer The Data

13 Richard P Feynman physicist playing the bongoes The Data

14 The Desired Output Turing, Alan Feynman, Richard Name: Alan Turing Born: 1912 Died: 1954 Professions: computer scientist, mathematician, cryptographer Hobbies: none known

15 Famous Scientists, Name: Born: Died:

16 Famous Scientists

17 ,

18 Name: Born: Died:

19 attribute value templates allows attribute values derived from the source to be set in the output example <name first = {first_name} initial = {middle_initial} last = {last_name} />

20 specifies a particular template to be invoked perhaps not related directly to a node-set –e.g. to add boilerplate start_html markup template must have a name attribute calls the template by name

21 <!Interesting stuff that generates the masthead goes in here --> … some-title

22 , defines parameters for templates parameters can be passed to templates from either call-template or apply-template elements containing elements name attribute names the parameter select attribute (or content) defines the value of the parameter

23 XSLT processing flow reference to template and parameter passed return to XSLT processing flow

24 150 …

25 allows values to be stored to assist with processing flow logic name attribute names the variable select attribute (or content) defines the value of the variable value can also be defined from element content

26 13 15 7, $y = 13 else $y = 15 -->

27 appears inside or inside sorts a node-set according to some criterion successive sort elements impose sub-orders select attribute defines the sorting criterion data-type defines the type of sort –text (the default) –number

28

29 more sort attributes order –ascending (default) –descending case-order –upper-first –lower-first

30 document ( ) converts a parameter into a URI –relative to current document –second parameter gives an alternative base URI returns a node-set associated with the URI allows content to be extracted from multiple XML documents without parameter defaults to current document

31 multiple XML files XSLT document XSLT processor output document set of template rules match elements and replace using template rules XML source XML source XML source XML source XML source XML source master document document()

32 Fridge Contents XML XSLT

33 XSLT extensions extension elements are passed to external code (extension functions) for processing –Java, Perl, C# etc. extends power of XSLT to arbitrary transformations implementation varies between XSLT processors –Xalan, Saxon, XT all allow extensions, but in different ways

34 Useful websites Standards: –www.w3.org/Style/XSL/- administrates xsl std www.w3.org/TR/xslt Tutorials/Forums –www.w3schools.com/xsl –www.learn-xslt-tutorial.com/ –www.xml.com –www.tizag.com/xmlTutorial/xslttutorial.php


Download ppt "Advanced XSLT II. Iteration in XSLT we sometimes wish to apply the same transform to a set of nodes we iterate through a node set the node set is defined."

Similar presentations


Ads by Google