On Day 14, “JSP Tag Libraries,” you developed a custom tag library for use with your Web application. Today, you will write an XSLT stylesheet that will transform a Tag Library Descriptor (TLD) document into an HTML page for easy viewing.
Listing 17.19 shows the agency.tld file from Day 14 that you will transform into HTML for display by a Web browser.
1: <?xml version="1.0" encoding="ISO-8859-1" ?> 2: <!--DOCTYPE taglib PUBLIC 3: "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" 4: "http://java.sun.com/dtd/web-jsptaglibrary_1_2.dtd"--> 5: <taglib> 6: <tlib-version>1.0</tlib-version> 7: <jsp-version>1.2</jsp-version> 8: <short-name>agency</short-name> 9: <tag> 10: <name>getJob</name> 11: <tag-class>web.GetJobTag</tag-class> 12: <body-content>empty</body-content> 13: <variable> 14: <name-given>job</name-given> 15: <variable-class>agency.AdvertiseJob</variable-class> 16: <declare>true</declare> 17: <scope>AT_BEGIN</scope> 18: </variable> 19: <attribute> 20: <name>ref</name> 21: <required>true</required> 22: <rtexprvalue>true</rtexprvalue> 23: </attribute> 24: <attribute> 25: <name>customer</name> 26: <required>true</required> 27: <rtexprvalue>true</rtexprvalue> 28: </attribute> 29: </tag> 30: <tag> 31: <name>getCust</name> 32: <tag-class>web.GetCustTag</tag-class> 33: <body-content>empty</body-content> 34: <variable> 35: <name-given>cust</name-given> 36: <variable-class>agency.Advertise</variable-class> 37: <declare>true</declare> 38: <scope>AT_BEGIN</scope> 39: </variable> 40: <attribute> 41: <name>login</name> 42: <required>true</required> 43: <rtexprvalue>true</rtexprvalue> 44: </attribute> 45: </tag> 46: <tag> 47: <name>forEachJob</name> 48: <tag-class>web.ForEachJobTag</tag-class> 49: <body-content>JSP</body-content> 50: <variable> 51: <name-given>job</name-given> 52: <variable-class>agency.AdvertiseJob</variable-class> 53: <declare>true</declare> 54: <scope>AT_BEGIN</scope> 55: </variable> 56: <attribute> 57: <name>customer</name> 58: <required>true</required> 59: <rtexprvalue>true</rtexprvalue> 60: <type>agency.Advertise</type> 61: </attribute> 62: </tag> 63: <tag> 64: <name>forEach</name> 65: <tag-class>web.ForEachTag</tag-class> 66: <body-content>JSP</body-content> 67: <attribute> 68: <name>collection</name> 69: <required>true</required> 70: <rtexprvalue>true</rtexprvalue> 71: <type>java.util.Collection</type> 72: </attribute> 73: </tag> 74: <tag> 75: <name>option</name> 76: <tag-class>web.OptionTag</tag-class> 77: <tei-class>web.OptionTagTEI</tei-class> 78: <body-content>empty</body-content> 79: <attribute> 80: <name>selected</name> 81: <required>false</required> 82: <rtexprvalue>true</rtexprvalue> 83: <type>java.util.String[]</type> 84: </attribute> 85: <attribute> 86: <name>default</name> 87: <required>false</required> 88: <rtexprvalue>true</rtexprvalue> 89: <type>java.util.String</type> 90: </attribute> 91: </tag> 92: </taglib> |
To display this TLD document, you will need to write a stylesheet that defines rules for the following transformations:
Put the tag library name in a <H1> element.
Define a <TABLE border="1"> to contain all the tags.
Highlight each tag name using a <STRONG> element.
Put each tag in a row in the table and put the name, body content, all the attributes and all the variables each in their own cell.
Put the attribute lists in their own table.
Put the variable lists in their own table.
Listing 17.20 shows a suitable HTML page containing one row that meets the previously listed requirements.
1: <HTML> 2: <HEAD> 3: <META http-equiv="Content-Type" content="text/html; charset=UTF-8"> 4: <TITLE>agency TLD</TITLE> 5: </HEAD> 6: <BODY> 7: <H1>Tag Library Name: agency</H1> 8: <TABLE border="1"> 9: <TR align="left" valign="top"> 10: <TH colspan="2">Tag</TH><TH>Attributes</TH><TH>Variables</TH> 11: </TR> 12: <TR align="left" valign="top"> 13: <TH>Name</TH><TH>Body</TH><TH>Name Required</TH><TH>Name Class</TH> 14: </TR> 15: <TR align="left" valign="top"> 16: <TD><STRONG>getJob</STRONG></TD><TD>empty</TD><TD> 17: <TABLE> 18: <TR align="left" valign="top"> 19: <TD>ref</TD><TD>true</TD> 20: </TR> 21: <TR align="left" valign="top"> 22: <TD>customer</TD><TD>true</TD> 23: </TR> 24: </TABLE> 25: </TD><TD> 26: <TABLE> 27: <TR align="left" valign="top"> 28: <TD>job</TD><TD>agency.AdvertiseJob</TD> 29: </TR> 30: </TABLE> 31: </TD> 32: </TR> 33: </TR> 34: </TABLE> 35: </BODY> 36: </HTML> |
Finally, Figure 17.4 shows a screen snapshot of how your transformed HTML page should appear in a Web browser.
3.145.202.27