If these color IDs and names were in a table, you could think of the table as the "colorNumKey" lookup table, the nodes named by the match attribute as the rows of the table, and the value or values named by the use attribute as the index field or fields of the table. These color elements would fit nicely into a table, but the beauty of doing this with XSLT and XML is that the elements named by your match attribute can have structures that are much more complex than any relational database table row.
You have the full power of XML available, and the ability to use an XPath expression in the use attribute lets you identify any part of that structure you want to use as the lookup key.
The key function performs the actual lookup. It takes a value, searches through the keys for one whose use value is equal to the one it's looking for, and returns the element or elements that have that key value. The example's template rule for the shirt elements calls this function to insert the color name before each shirt element's contents.
The two arguments it passes to this function are the name of the key "colorNumKey", the name of the lookup "table" and the value to use to look up the needed value: the shirt element's colorCode attribute value.
Because the key function returns the node or nodes that the lookup found, you can use the function call as part of an XPath expression to pull an attribute value, subelement, or other subnode out of the returned node. Because the entire color node was used in the example above, its character data contents the part between the color start- and end-tags got added to the result tree. Let's experiment with this color lookup table a little more.
The Extensible Stylesheet Language Family (XSL)
The following template demonstrates several things you can do with declared keys in XSLT using the same shirts source document as the last example. The first three xsl:value-of instructions use the same "colorNumKey" key that the previous example did. The first xsl:-value-of instruction passes the literal string "c3" as the index value to look up, and the result shows that "c3" is the key for the color "red". The second shows how a variable can be used for this argument to the key function: an xsl:variable instruction near the beginning of the stylesheet declares a testVar variable with a value of "c4", and when the XSLT processor uses this variable to look up a color name, the result shows that this finds the color "blue".
The third xsl:value-of instruction in the stylesheet passes the string "c8" to use for the lookup, and there is no color element with a cid attribute value of "c8", so nothing shows up in the result tree after "c8's color:". The next part of the template looks up the value "c7".
The document has two color elements with a cid value of "c7", so the template uses an xsl:for-each instruction instead of an xsl:value-of one to add both of them to the result tree. If it had used xsl:value-of , only the first would have appeared in the result. A key function can return multiple nodes, and this one does, so the xsl:for-each instruction iterates through the "c7" nodes, printing the value and a space using an xsl:text element for the latter for each. Automating Stylesheet Creation. Appreciating Libxslt. Details about the various types of supported documents and their unique editing features.
The requirements and installation instructions for each platform. General information about working with any type of document.
A concise user's guide and tutorial
Details about transformation scenarios and customizing various types of output. Describes how to use the Archive Browser to work with various type of archives.
How to import data from various external sources into XML documents. Tutorials and details about customizing frameworks and the visual Author editing mode. A compilation of common problems and their solutions. A guide to help content authors who create and publish DITA content. Legal information. The Oxygen XML Editor Quick Fix support helps you resolve various errors that appear in a stylesheet by proposing Quick Fixes to problems such as missing templates, misspelled template names, missing functions, or references to an undeclared variable or parameter.
- Computational and visualization techniques for structural bioinformatics using chimera.
- An introduction to keys.
- Rama Beyond Price (Clay Sanskrit Library)!
- liveBook · Manning!
- Download Xslt Quickly 2001?
To activate this feature, hover over or place the cursor in the highlighted area of text where a validation error or warning occurs. If a Quick Fix is available for that particular error or warning, you can access the Quick Fix proposals with any of the following methods: When hovering over the error or warning, the proposals are presented in a tooltip pop-up window.
If you place the cursor in the highlighted area where a validation error or warning occurs, a Quick Fix icon is displayed in the stripe on the left side of the editor. Forum: Book Reviews.
Subscribe to RSS
Johannes de Jong. This book, as the author put it, provides "task-oriented explanations of how to get work done with XSLT". Part 1 has a brief tutorial, but it is not the strongest part of this book. Part 2 is what makes this book worth the read - it delves into most typical tasks, or even classes of tasks, XSLT developers encounter: adding, changing, deleting elements and attributes, sorting, avoiding duplicates and many other.
- Your Answer.
- Environmental Economics for Non-Economists;
- Famine, Disease and the Social Order in Early Modern Society.
- Searching the Chemical Literature (Advances in Chemistry Series 004)?
- Advances in Geophysics, Vol. 2.
- Online XSLT Editor;