XML and XSLT
- Warning: Browser caches!! Browsers will sometimes cache old versions of the files you use (especially your sample XML and your XSL files). If things aren't working right, clear the history/cache. This is likely to happen to you, so make note of this issue!
NOTE: read these instructions first, BUT then see the plan of attack below, before you start!
This lab really only requires two things: the ability to insert data, and the ability to query the data. The insertion can simply be from your Lab 4, and the query must follow the requirements below:
- DB Insert: You must be able to insert data into your database from the webpage. Use your previous lab!
- XSLT Display: There should be a button or something to interact with such that the following happens:
- The Perl returns an XML document (see details below). Namespaces are not required for this XML.
- You transform that XML with XSLT (see details below).
- You display part of the transformed XML in your page.
- All of this should happen within your original index.html (e.g., the URL up top should not change)
- XML Data: The details of the XML produced by your DB are up to you. However, it should contain at a minimum:
- Results for at least 3 distinct "things" (e.g. people, products, events) (including all items from your DB is okay too)
- Contain at least 2 distinct attributes or sub-elements "about" each thing (e.g., if your "thing" is a person, then the name and company of each person would each count here).
- Adding new results to the DB (using your existing functionality) should cause the XML result to change (e.g., if you add a new person, that person should appear in the XML produced).
- XSLT Specs: The details of the XSLT transformation are up to you. It should however at a minimum:
- Do some re-orderings (e.g. not display things in exactly the same order as the XML file)
- Insert some HTML markup
- Contains results for at least 3 distinct "things"
- Show the info from at least 2 distinct attributes/elements "about" each thing
- Your XSLT should not be too similar to the given examples.
- Testing Files: For testing and grading purposes, you must make (and keep around) two test files. You must keep this up to date if you change your XML later!
- test1.xml - sample XML in exactly the same format that your Perl program produces.
- test2.xml - identical to test1.xml, except it has the line in it that causes the browser to transform it with your XSL file before displaying the results.
- Code Comments: As always, your code must be commented!
- Instructions: On your default.htm page, provide some instructions on how to use your site. What exactly do I click/enter to add to your database? What exactly do I click to retrieve the XML data?
- Links: On your default.htm page, have the following links:
- Link to test1.xml
- Link to test2.xml
- Link to invoke to your Perl file that generates the XML. Provide arguments (if necessary) - so if you click on this link, you should see XML appear in the browser, and the XML should be in the same format as test1.xml and test2.xml (it's okay if the data is a little different).
- Link to Lab06/index.html (as you usually would have)
- Validate: Ensure all your pages validate and that you have met all requirements.
Suggested plan of attack
Do NOT write any Perl/PHP code until you have finished these steps:
- Copy your Lab04 files (or Lab05, if you continued your theme in Lab05) to a new Lab06 directory. Your main file should still be called index.html
- Create a dummy XML file called test1.xml that approximates what you WANT to produce from your database. You do not have to have namespaces in this file.
- Verify that test1.xml is valid by loading it in a browser. A complaint about namespaces is okay, but it should be rendered as valid XML.
- Create your XSLT file. Suggestion: start with the "Example 0.5" XSL from the online example page.
- COPY test1.xml to test2.xml. Now test your XSLT file by adding the appropriate line to your test2.xml XML file (not test1.xml) and loading it in a browser. Does an HTML page now display?
B. Perl and DB
- Write the Perl code to actually produce real XML based on querying your DB.
- Type in the Perl script as the URL in your browser. Does it display as valid XML data? Do not move on until it does.
- Interact with your webpage. Does the XML appear reformatted on your page? Do not move on until it does.
- Now make sure that the user can add content to the database and have that content show up in the results of the transformed XML.
- Write the default.htm instructions
- In default.htm, add the links to test1.xml, test2.xml, and to invoke Perl to generate XML (see details in requirements above)
- Important:: go back and check that
- test1.xml and test2.xml have identical content (only differ in a processing instruction)
- test1.xml and test2.xml match the XML format produced by your Perl program
- test1.xml renders as valid XML in the browser
- test2.xml shows the transformed result (e.g. changed by XSLT) when loaded in the browser
- See the plan of attack above!
- For problems with perl, see tips about creating Perl files.
- As always, the "Console" in Chrome is invaluable for errors.
- On the command line, database errors will usually appear automatically. From the browser, they won't - instead insert this as a debug:
- Useful SQL examples:
- CREATE TABLE comments (USER_NAME VARCHAR(20), TIMESTAMP DATETIME, COMMENT MEDIUMTEXT, PAGE INTEGER);
- INSERT INTO comments (USER_NAME, TIMESTAMP, COMMENT, PAGE) VALUES ('Jamie', '2006-09-27 11:30:00', 'hi', 2);
- CREATE TABLE topics (TOPIC VARCHAR(20), OWNER VARCHAR(20));
- INSERT INTO topics (TOPIC, OWNER) VALUES ('Cars', 'Jamie');
- Note: ID is automatically created with the table, no need to specify it.
- Do not use the die() function alone - the error it generates can't be seen from your web page.
- All of your files for Lab06 should be in a folder called "it452/Lab06" on the Web drive.
- Your main page for Lab06 should be called "index.html" and placed inside the folder "it452/Lab06".
- All files must be complete and saved to your Web drive before you submit the hardcopy of your assignment. Do NOT modify your files after you have submitted your assignment.
- Turn in the following hardcopy on or before the due date, stapled together in the following order (coversheet on top):
- A completed assignment coversheet.
- The first page of the output of the W3C validator, as run on the final version of your Lab06/index.html. This should show that your document correctly validated, but turn it in anyway if you can't get your page to validate.
- A printout of the source to your Lab06/index.html file.
- A printout of your Perl/PHP file that generates XML.
- A printout of test2.xml
- A printout of your XSLT file.