Go Back   CodingForums.com > :: Client side development > XML

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 10-18-2012, 11:29 AM   PM User | #1
pomme123
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pomme123 is an unknown quantity at this point
need help on transforming XML to XHTML through XLST

Hey guys, how you doing.

Ive been trying to pick up coding for a while now and have really found it difficult, i have been given a task by my uni to complete by tomorrow but man, i cant do it, i was wondering if i could get any help from you guys, its part of an assignment ive been given.

anyways, without further a due, here is my XML file. (its a biggie, sorry, and it probably isnt that good cause, well, i suck at this, haha)

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE recipes [
<!ELEMENT recipe (dish+)>
<!ELEMENT dish (name, type, preptime, cooktime, utensils+, instructions, bestbev?, condiments*, creator*)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT type (category, nationality*)>
<!ELEMENT category (Dishtype, ingredients)>
<!ELEMENT dishtype (#PCDATA)>
<!ELEMENT ingredients (mainingredient, otheringredients+)>
<!ELEMENT mainingredient (imageingredient, URLinfoingredient)>
<!ELEMENT otheringredients (#PCDATA)>
<!ELEMENT imageingredient (#PCDATA)>
<!ELEMENT URLinfoingredient (#PCDATA)>
<!ELEMENT nationality (#PCDATA)>
<!ELEMENT preptime (#PCDATA)>
<!ELEMENT cooktime (oventemp, time)>
<!ELEMENT oventemp (#PCDATA)>
<!ELEMENT time (#PCDATA)>
<!ELEMENT utensils (#PCDATA)>
<!ELEMENT instructions (preperation+, cooking)>
<!ELEMENT preperation (#PCDATA)>
<!ELEMENT cooking (#PCDATA)>
<!ELEMENT bestbev (#PCDATA)>
<!ELEMENT condiments (#PCDATA)>
<!ELEMENT creator (traditional | (restaurant*, firstname, surname, imagecreator*))>
<!ELEMENT traditional (#PCDATA)>
<!ELEMENT restaurant (name, location+)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT location (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT imagecreator (#PCDATA)>
]>
<recipe>
<dish>
<name>Prawn, cucumber and bean starter</name>
<type>
<category>
<dishtype>starter</dishtype>
<ingredients>
<mainingredient>Prawn</mainingredient>
<imageingredient>http://www.taste.com.au/images/recipes/sfi/2007/12/18570_n.jpg</imageingredient>
<URLinfoingredient>http://en.wikipedia.org/wiki/Prawns</URLinfoingredient>
<otheringredient>300g Green beans, trimmed and thinly sliced</otheringredient>
<otheringredient>2 Large lebanese Cucumbers</otheringredient>
<otheringredient>1.5Kgs Cooked King Prawns, Tails intact</otheringredient>
<otheringredient>1/3 cup olive oil</otheringredient>
<otheringredient>2Tbs Lemon Juice</otheringredient>
<otheringredient>2Tbs Chopped fresh Dill Sprigs</otheringredient>
<otheringredient>2Tsp Wholegrain Mustard</otheringredient>
</ingredients>
</category>
<nationality>Australian</nationality>
</type>
<preptime>15 mins</preptime>
<cooktime>
<time>30 secs</time>
</cooktime>
<utensils>knife, chopping board, jug, saucepan, calendar</utensils>
<instructions>
<preperation>Cook beans in a large saucepan of boiling water for 30 seconds or until just tender. Refresh in cold water. Drain.</preperation>
<preperation>Make dressing: Combine ingredients in a screw-top jar. Season with salt and pepper. Secure lid. Shake to combine.</preperation>
<preperation>Combine beans, cucumber and prawns in a large bowl. Pour over dressing. Toss to combine. Serve.</preperation>
</instructions>
<bestbev>White Wine, a nice fruity number</bestbev>
<condiments>none</condiments>
<creator>
<traditional>this is a traditional dish</traditional>
</creator>
</dish>
<dish>
<name>Egg and Lettuce Cups</name>
<type>
<category>
<dishtype>starter</dishtype>
<ingredients>
<mainingredient>Egg</mainingredient>
<imageingredient>http://www.taste.com.au/images/recipes/agt/2007/11/18401_n.jpg</imageingredient>
<URLinfoingredient>http://en.wikipedia.org/wiki/Eggs</URLinfoingredient>
<otheringredient>4 Eggs</otheringredient>
<otheringredient>1tsp Mayonaise</otheringredient>
<otheringredient>1.5Kgs Cooked King Prawns, Tails intact</otheringredient>
<otheringredient>1/4tsp Curry Powder</otheringredient>
<otheringredient>12 baby cos lettuce leaves</otheringredient>
</ingredients>
</category>
<nationality>Chinese</nationality>
</type>
<preptime>15 mins</preptime>
<cooktime>
<time>10 mins</time>
</cooktime>
<utensils>knife, chopping board, saucepan, calendar</utensils>
<instructions>
<preperation>Place eggs in a saucepan and cover with cold water. Bring to the boil over high heat. Cook for 4 minutes. Drain and cover with cold water. Set aside to cool. Peel. Place in a bowl. Use a fork to mash. Stir in mayonnaise and curry powder, if desired. Arrange baby cos lettuce leaves on serving plates. Spoon in the egg mixture. Serve.</preperation>
</instructions>
<bestbev>Glass of cold water</bestbev>
<condiments>none</condiments>
<creator>
<traditional>this is a traditional dish</traditional>
</creator>
</dish>
<dish>
<name>Barbecued asparagus with pink peppercorn dressing</name>
<type>
<category>
<dishtype>starter</dishtype>
<ingredients>
<mainingredient>Asparagus</mainingredient>
<imageingredient>http://www.taste.com.au/images/recipes/nb/2010/04/24712_n.jpg</imageingredient>
<URLinfoingredient>http://en.wikipedia.org/wiki/Asparagus</URLinfoingredient>
<otheringredient>2 1/2 tbs light olive oil</otheringredient>
<otheringredient>2 bunches asparagus, trimmed</otheringredient>
<otheringredient>2 tbs red wine vinegar</otheringredient>
<otheringredient>1 tsp honey</otheringredient>
<otheringredient>1 tsp Dijon mustard</otheringredient>
<otheringredient>1 shallot, finely chopped</otheringredient>
<otheringredient>1 tbs pink peppercorns, lightly crushed</otheringredient>
</ingredients>
</category>
<nationality>French</nationality>
</type>
<preptime>5 mins</preptime>
<cooktime>
<time>5 mins</time>
</cooktime>
<utensils>knife, chopping board, jug, saucepan, calendar</utensils>
<instructions>
<preperation>Heat a char-grill pan on high. Drizzle 2 teaspoons of the oil over the asparagus. Add the asparagus to the char-grill and cook, turning occasionally, for 2 minutes or until bright green and tender crisp. Transfer to a plate.</preperation>
<preperation>Place the remaining oil, vinegar, honey, mustard, shallot and peppercorns in a screw-top jar and shake until well combined. Season with salt and black pepper. Drizzle over the asparagus and serve immediately.</preperation>
</instructions>
<bestbev>White Wine, a nice fruity number</bestbev>
<condiments>none</condiments>
<creator>
<traditional>this is a traditional dish</traditional>
</creator>
</dish>


</recipe>


what im really looking for is someone to help me with the process to turn this into a good looking xhtml file. Thanks a lot in advance if anyone decides to take on a little task.
pomme123 is offline   Reply With Quote
Old 10-18-2012, 11:36 AM   PM User | #2
pomme123
New to the CF scene

 
Join Date: Oct 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
pomme123 is an unknown quantity at this point
and just for extra reference, this is what they're asking of me

You will be writing an XSLT document to transform your XML recipe pages from Assignment 1 into XHTML. The XHTML that is generated should fit in with the style of the rest of your website (ie similar formatting, colors, etc). You will need to use CSS in your generated XHTML.

Note that all your XML recipe pages have the same tags and DTD and therefore they can all use the same XSLT document. This means you should only make 1 XSLT file. The XSLT should have the following;
A heading which mentions the category you used for your recipe pages in Assignment 1 (entree, dessert, snacks)
List of all the recipes, sorted alphabetically by main ingredient and including the following.
The main ingredient
Link to the website/s (if any) related to the main ingredient.
An image of the dish.
All extra data that you stored for each recipe, such as other ingredients, preparation, ...
All these data must be collected from the XML person pages.
Any other information that is in your XML files.

thanks again guys, hope someone can help.
pomme123 is offline   Reply With Quote
Old 10-18-2012, 11:34 PM   PM User | #3
sunfighter
Senior Coder

 
Join Date: Jan 2011
Location: Missouri
Posts: 2,495
Thanks: 18
Thanked 361 Times in 360 Posts
sunfighter is on a distinguished road
To your xml add this
Code:
<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="Put the Name you want HERE.xsl"?>
<recipe>
This is not styled nor has everything you need, but if you can't finish this you need the bad grade:
Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
<html>
<body>
<table border="1">
<xsl:for-each select="recipe/dish">
<tr>
<td><xsl:value-of select="type/category/dishtype"/></td>
</tr><tr>
<td><xsl:value-of select="name"/></td>

<td><img>
  <xsl:attribute name="src">
    <xsl:value-of select="type/category/ingredients/imageingredient"/>
  </xsl:attribute>
</img></td>

<td><a href="{type/category/ingredients/URLinfoingredient}">
<xsl:value-of select="type/category/ingredients/URLinfoingredient"/>
</a></td>

<td><xsl:value-of select="type/category/ingredients/mainingredient"/></td>
<td><xsl:value-of select="cooktime"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
sunfighter is offline   Reply With Quote
Reply

Bookmarks

Tags
xhtml, xml

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:45 PM.


Advertisement
Log in to turn off these ads.