Bakumba Posted May 26, 2006 Share Posted May 26, 2006 Hi,Im trying to create a stylesheet to show a 'mailbox' xml file (a xml file with a series of email messages) with a table accomodating each email address. below is what i have but its not working:the xml file:<?xml version='1.0'?><?xml-stylesheet type="text/xsl" href="email.xsl" ?><mailbox><email><from><name>Les Carr</name> <address>lac@ecs.soton.ac.uk</address></from><to><name>Hugh Davis</name> <address>hcd@multicosm.com</address></to><subject>Teaching Duties</subject><content>Using Java to teach Programming Principles seems to have worked verywell. The standard of software engineering seems to have increased.</content></email><email><from><name>Wendy Hall</name> <address>wh@ecs.soton.ac.uk</address></from><to><name>Les Carr</name> <address>lac@ecs.soton.ac.uk</address></to><subject>XML Course</subject><content>Please make sure that you use the new IAM logo on all ourcourse material.</content></email><email><from><name>Les Carr</name> <address>lac@ecs.soton.ac.uk</address></from><to><name>Wendy Hall</name> <address>wh@ecs.soton.ac.uk</address></to><subject>Re: XML Course</subject><content>Have you looked at the content?</content></email></mailbox>the .xsl file<?xml version='1.0'?><xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" ><xsl:template match="*"> <xsl:apply-templates/></xsl:template><xsl:template match="/"> <H1>Email Listing</H1> <xsl:for-each select="mailbox/email"> <table> <xsl:apply-templates/> </table> </xsl:for-each></xsl:template><xsl:template match="//from"> <tr><td>From:</td><td><xsl:value-of select="name"/> (<xsl:value-of select="address"/>)</td></tr></xsl:template><xsl:template match="//to"> <tr><td>To:</td><td><xsl:value-of select="name"/> (<xsl:value-of select="address"/>)</td></tr></xsl:template><xsl:template match="//subject"> <tr><td>Subject:</td><td><xsl:value-of select="."/> </td></tr></xsl:template><xsl:template match="//content"> <tr><td colspan="2"><xsl:value-of select="."/></td></tr></xsl:template></xsl:stylesheet>Can someone kindly let me know where im being stupid?Thanks a lot Link to comment Share on other sites More sharing options...
boen_robot Posted May 26, 2006 Share Posted May 26, 2006 Well, the first errors I notice are1. The XSLT namespace. It's actually http://www.w3.org/1999/XSL/Transform And nothing else. The namespace you're trying to use causes unstandart behaviour.2. The templates from, to, subject and content could as well exist and apply without the "//". The apply-templates element inside the "/" tepmlate is going to call them anyway.3. Speaking of the template "/", wouldn't it be better if it actually contains the wrapper and calls the mailbox, like this: <xsl:template match="/"><html><head><title>Emails</title></head><body><xsl:apply-templates/></body></html></xsl:template><xsl:template match="mailbox"><H1>Email Listing</H1><xsl:for-each select="email"><table><xsl:apply-templates/></table></xsl:for-each></xsl:template> Try fixing theese, and I'll see later on if something is wrong. Link to comment Share on other sites More sharing options...
Bakumba Posted May 26, 2006 Author Share Posted May 26, 2006 Well, the first errors I notice are1. The XSLT namespace. It's actuallyhttp://www.w3.org/1999/XSL/Transform And nothing else. The namespace you're trying to use causes unstandart behaviour.2. The templates from, to, subject and content could as well exist and apply without the "//". The apply-templates element inside the "/" tepmlate is going to call them anyway.3. Speaking of the template "/", wouldn't it be better if it actually contains the wrapper and calls the mailbox, like this: <xsl:template match="/"><html><head><title>Emails</title></head><body><xsl:apply-templates/></body></html></xsl:template><xsl:template match="mailbox"><H1>Email Listing</H1><xsl:for-each select="email"><table><xsl:apply-templates/></table></xsl:for-each></xsl:template> Try fixing theese, and I'll see later on if something is wrong. <{POST_SNAPBACK}> Hi, thanks for the reply.Tried implementing your changes but it doesnt work. im only getting the following when opening the XML file using IE:Email ListingFrom: () To: () Subject: any ideas?thanks Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now