XSLT Flashcards
What is XSLT and why is it used (especially over DOM)?
DOM can be overkill for small transformations. XSLT allows you to modify the structure without expensive Java methods.
- Uses XML Syntax
- The use of XPATH lets you navigate through the tree
- Can complete lots of transformations (generation/duplication/moving etc)
- Can calculate new content or structure based on the source code
XSLT is stylesheet transformation.
Why can’t you use it in place of CSS?
XSLT doesn’t actually change the style of the XML in the same sense as CSS but changes the styles structure.
XSLT transform one DTD/Schema to another!
XSLT + CSS = STYLE
How do you start writing xslt?
Start with a namespace (shown attached).
In XPATH, what is the Context Node?
The context is the Current Node (current pointer)
What are XPATH navigation expressions?
Tip: There are 10.
Each of these expressions start from the context node unless specified.
- . : selects context node
- .. : parent of the context
- // : all descendants of the context node
- foo : all child nodes with the name ‘foo’
- @foo :all attributes of context with name ‘foo’
- * : selects all child nodes
- @* :selects all attributes of the context
- text() : selects the value of only the text child nodes.
- node() : selects all child node values regardless of type.
- / : selects the root
Examples:
../chapter/title/@subtitle
//note/text()
What are predicates and show an example
Predicates allow you to filter on path expressions.
They can match against attributes or elements
Examples:
book/title[@subtitle=”or what you will”]
book[title=’Twelve Night’]
How do you add functions to Predicates?
Within the predicate.
book[count(chapter) > 10]
What would be the result of the attached xslt agasint the attached xml?
Answer attached.
The xslt transformation can happen at the client of the server.
We see the original source code when we apply on the Client Side. The browser has done the transformation for us.