Presentation is loading. Please wait.

Presentation is loading. Please wait.

© 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014.

Similar presentations


Presentation on theme: "© 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014."— Presentation transcript:

1 © 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014

2 | 2 || 2 | © 2013 The MITRE Corporation. All rights reserved. What is the position of the XSLT processor?  Suppose that the XSLT processor is streaming through an input document and has arrived at element N.  Thus, the current streaming position is the element.  Suppose the element has an attribute and a namespace declaration: …  Exactly where is the XSLT processor positioned? The answer to this question is important because it tells us what the XSLT processor has seen when it arrives at the element.

3 | 3 || 3 | © 2013 The MITRE Corporation. All rights reserved. What is the position of the XSLT processor?  Is the XSLT processor positioned here, after the name of the start tag: …  Is the XSLT processor positioned here, after the attribute value: …  Or is the XSLT processor positioned here, after the namespace declaration: …

4 | 4 || 4 | © 2013 The MITRE Corporation. All rights reserved. The XSLT processor is at the “>”  Answer: The XSLT processor is positioned at the start tag’s end angle bracket: …  So what? So the XSLT processor has seen the element name, its attributes, and its namespace declarations. Obviously it has not seen its content. This is a key concept!

5 | 5 || 5 | © 2013 The MITRE Corporation. All rights reserved. The XSLT processor remembers what it sees A "stack" of ancestor data is maintained as the streaming processor works its way through the document. Michael Kay xsl-list, 1/29/2014

6 | 6 || 6 | © 2013 The MITRE Corporation. All rights reserved. The XSLT processor remembers ancestors and self  Suppose an XSLT processor is at element N (that is, the current streaming position is the element). As the XSLT processor streams through the input, it remembers the start tags of all the ancestor nodes, finally arriving at element N. A B C DE N F Current streaming position The XSLT processor remembers the start tags of all the ancestors of N: E, B, and A. This is a key concept!

7 | 7 || 7 | © 2013 The MITRE Corporation. All rights reserved. What does the XSLT processor remember?  The preceding slide said: The XSLT processor remembers the start tags of all the ancestors of N: E, B, and A.  Question: Exactly what does the XSLT processor remember?  Answer: It remembers the names of the elements, the names of the attributes, the values of the attributes, and the namespaces that are visible. This is a key concept!

8 | 8 || 8 | © 2013 The MITRE Corporation. All rights reserved. Definition of Climbing  A construct is climbing if, when executed, it results in reading information from the "stack" of ancestor data that is maintained by the XSLT processor as it works its way through the input.

9 | 9 || 9 | © 2013 The MITRE Corporation. All rights reserved. Why is it called “climbing”?  The term “climbing” comes from the notion that a climbing construct is one that climbs up the XML tree.

10 | 10 | © 2013 The MITRE Corporation. All rights reserved. Climbing examples  Suppose that this XML document is being stream-processed: A book about... http://www.book.org Hello World  Suppose that the current streaming position is the element.  This XPath expression: @* returns all the attributes of Title; @* is a climbing construct.  This XPath expression: ancestor::* returns all the ancestors of Title; ancestor::* is a climbing construct.

11 | 11 | © 2013 The MITRE Corporation. All rights reserved. Climbing examples (cont.)  This XPath expression:../@* returns all the attributes of the parent of Title;../@* is a climbing construct.  This XPath expression:./namespace::* returns all the namespaces visible on Title;./namespace::* is a climbing construct.

12 | 12 | © 2013 The MITRE Corporation. All rights reserved. Operating on the results of a climbing construct  What can be done with the nodes returned by a climbing construct?  We must be careful because the XSLT processor remembers only a limited amount of information about the ancestor nodes.  We can apply the name() function to the parent: name(..)  We can obtain the name of each ancestor element: for $i in ancestor::* return name($i)  We can obtain the value of each attribute of Title: for $i in @::* return data($i)

13 | 13 | © 2013 The MITRE Corporation. All rights reserved. Can’t apply the string() function to an ancestor element  This is not legal (not streamable): apply string() to the grandparent: string(../..) Element Book Text Hello World Element Intro Element Chapter Element Title xml:lang= " EN " Text A book about … id= " abc " xmlns= " http://www.book.org " Current streaming position Fetching this would require the XSLT processor back up. Backing up is not allowed in streaming. Executing string(../..) would result in the XSLT processor attempting to obtain all this data.

14 | 14 | © 2013 The MITRE Corporation. All rights reserved. Lesson Learned  So you write an XPath expression to climb up the XML tree.  That XPath expression is a “climbing construct.”  Good so far.  Now you operate on those nodes that your climbing construct fetched.  Be sure the operation doesn’t result in consuming the children of those nodes. Key concept: you are allowed to ascend but not allowed to descend afterwards.

15 | 15 | © 2013 The MITRE Corporation. All rights reserved. Okay to apply the string() function to an ancestor element’s attribute  It is legal to apply the string() function to an ancestor element’s attributes. For example, this is legal: string(../@id) Element Book Text Hello World Element Intro Element Chapter Element Title xml:lang= " EN " Text A book about … id= " abc " xmlns= " http://www.book.org " Executing string(../@id) would result in the XSLT processor attempting to obtain this data. That’s okay because it is data that the XSLT processor remembered on its journey to Title. Current streaming position

16 | 16 | © 2013 The MITRE Corporation. All rights reserved. Question: Does context node equals current streaming position?  Answer: The context node is not always equal to the current streaming position.  Suppose the XSLT processor is streaming through an input document and has arrived at element N. The element is the current streaming position and also the context node.  Now suppose the XSLT program instructs the XSLT processor: From your current streaming position climb the XML tree and return the name of each ancestor element: The context node changes with each iteration of the for-each statement. But the current streaming position remains the same. This is a key concept!

17 | 17 | © 2013 The MITRE Corporation. All rights reserved. Descend then ascend is climbing  Recall that a climbing construct is one that reads information remembered by the XSLT processor.  Consider a construct that descends (the XSLT processor will remember things) and then ascends (the XSLT processor reads information that it remembered). That is a climbing construct!  So this is a climbing construct: descendant::x/parent::y


Download ppt "© 2013 The MITRE Corporation. All rights reserved. XSLT Streaming Terminology Understanding “Climbing” Roger L. Costello, February 3, 2014."

Similar presentations


Ads by Google