- Configure the Server
- Server-side Transformations
- Allowing the User to Choose the Style Sheet
- Saving User Choices
- Using the User's Preferred Information
- Applying the Style Sheet to Other Pages
- Summary
Applying the Style Sheet to Other Pages
By itself, this is a nice way to give the user control over the look and feel of the home page, but we can also use their style sheet choice on the rest of the site's pages.
Because the transformation is simply taking in a source and a style sheet, we can provide any source we want, and it will be used to create the new page.
Other Pages in ASP
It's most likely that a reference to other content will be made as part of a link, so to get the information, we'll check the QueryString, as shown in these changes in main.asp:
<%@ language = "VBSCRIPT" %> <% 'Set source files if Request.QueryString("content") = "" then contentfile = "content.xml" else contentfile = Request.QueryString("content") end if sourceFile = Server.MapPath(contentfile) if Request.Cookies("stylechoice") = "" then stylesheet = "style1.xsl" ...
If there is no reference to a content value in the QueryString, we'll simply use the main content page. Otherwise, we'll use the requested XML file.
Other Pages in Java
The changes necessary are straightforward, and are included in main.java (and main.class):
... try { //Set source files String XMLFileName = "http://localhost/"; if (request.getParameter("content")== null) { XMLFileName = XMLFileName + "content.xml"; } else { XMLFileName = XMLFileName + request.getParameter("content"); } StreamSource source = new StreamSource(XMLFileName); String XSLFileName = ""; ...
First, we set the XMLFileName variable to the basic location. If no content parameter was sent, we'll use the original content file. Otherwise, we'll use the requested file.
The Result
To see the results, click the "new pilot" link in the first news item. This link includes the content value, so when the page loads, the page pulls up not the original gossip information, but the news file that was specified, as shown in Figure 4.
Figure 4 The main page can be used to load any appropriate content.
You can also change the layout from this page, as shown in Figure 5 and 6:
Figure 5 Users can change the overall layout from anywhere on the site.
Figure 6 Users can change the overall layout from anywhere on the site, too.
Click the top logo to return to the home page, and notice that no matter where you make the change to the layout, it is applied to either page.