XML - Managing Data Exchange/C.6

president.xsl (XSL Stylesheet for a one-to-one model)
Now that you now how to create a schema to define a conceptual primary/foreign key relationship, you need to know how to access and display that data. Take a look at the stylesheet below for an example.   Table 6-3: XML stylesheet for President Entity – president.xsl

A look at the new elements:

 * &lt;xsl:key&gt; This element is a necessary declaration in order to use the key function described next. There are three necessary attributes to be used in this element:
 * name : This attribute contains the name to be referenced from within XSL file in the key function. The value in the name attribute can be thought of in programmatic terms as a variable containing an instance of an object, such as: “String stringVariable” in Java.
 * match : This attribute is similar to the .&lt;xsd:selector&gt; element described above. This is the element in XML file containing the parent key (primary key of the relationship).
 * use : This attribute is similar to the &lt;xsd:field&gt; element describe above. This is the field containing the parent key value.
 * key(string,object) function: This function returns a node set based on the parameters passed to it. The string  parameter is the value defined in the name attribute in the &lt;xsl:key&gt; tag. The object  parameter is the value of primary key for which you wish to get the nodes for. key('predecessor',2) will return the nodes contained by the president element with attribute: primaryKey=&quot;2&quot; . Since a node set is returned, you can access child nodes of the returned set with an x-path expression just as you would any element. So: &lt;xsl:value-of select=&quot;key('predecessor',2)/firstName &quot;/&gt; would output “John.” For more information on the key function visit: http://www.w3.org/TR/xslt#key
 * &lt;xsl:choose&gt; This XSL element provides a means for creating an if-else type structure in an XSL stylesheet. This is necessary in our example because the first President will not have a predecessor. We display the predecessor if only there is one! There are two elements within the &lt;xsl:choose&gt; element to perform this:
 * &lt;xsl:when&gt; This element is the equivalent to the programmatic 'if' statement. The test attribute contains a test statement as described in chapter 5. In the above example, it is simply testing to see if the predecessor element is there (if a President has a predecessor).
 * &lt;xsl:otherwise&gt; This element is the equivalent to the programmatic 'else' statement. Its contents are displayed if the test condition in the &lt;xsl:when&gt; statement fails.

team.xsl (XSL Stylesheet for a one-to-many model)
   Table 6-4: XML stylesheer for Team Entity – team.xsl

A look at the new elements

 * &lt;!doctype stylesheet[….]&gt; - This declaration is necessary to declare an entity and must come before the &lt;xsl:stylesheet&gt; tag
 * &lt;!ENTITY space &quot;&lt;xsl:text xmlns:xsl='http://www.w3.org/1999/XSL/Transform'&gt; &lt;/xsl:text&gt;&quot;&gt; {2}- This declaration must come between the brackets “[]” in the doctype declaration shown above. “space” is the name of the entity you are defining. The value in between the double quotes is what the entity represents. In our example above, the entity space  is referring to a single whitespace, represented with the &lt;xsl:text&gt; &lt;/xsl:text&gt; statement. The xmlns  attribute located within the &lt;xsl:text&gt; element is only necessary for parsers using the Microsoft XML parser, but should be included anyway for cross compliance. The syntax for using the entity is the same syntax for using any other entity in an XSL stylesheet, which is an ampersand (“&amp;”) followed by the entity name and a semi-colon. In the example above, this would be &amp;space; as shown on. Now whenever a space is needed in the style sheet “&amp;space;” can be used instead of &lt;xsl:text&gt; &lt;/xsl:text&gt;

accessory.xsl (XSL stylesheet for a many-to-many model)
  N/A      <SMALL>Table 6-9: XML stylesheet for Accessory Entity – accessory.xsl</SMALL>