Click to See Complete Forum and Search --> : xslt
jiggs
04-29-2003, 02:47 PM
Hi everyone i need to write an XSLT document that transforms the XML of the following document into an XHTML sorted list????????????????????????????
SOMEONE PLLLLLLEEEEAAAASSSEEE HELPME ITS GOTME STUMPED!
Heres that document:
<?xml version="1.0"?>
<employees>
<employee>
<name>Name</name>
<job>Job</job>
<department>Department</department>
<cubicle>Cubicle</cubicle>
</employee>
<employee>
<name>Joe</name>
<job>Programmer</job>
<department>Engineering</department>
<cubicle>5E</cubicle>
</employee>
<employee>
<name>Erin</name>
<job>Designer</job>
<department>Marketing</department>
<cubicle>9M</cubicle>
</employee>
<employee>
<name>Melissa</name>
<job>Designer</job>
<department>Human Resources</department>
<cubicle>8H</cubicle>
</employee>
<employee>
<name>Craig</name>
<job>Administrator</job>
<department>Engineering</department>
<cubicle>4E</cubicle>
</employee>
<employee>
<name>Danielle</name>
<job>Programmer</job>
<department>Engineering</department>
<cubicle>12E</cubicle>
</employee>
<employee>
<name>Frank</name>
<job>Salesperson</job>
<department>Marketing</department>
<cubicle>17M</cubicle>
</employee>
<employee>
<name>Corinne</name>
<job>Programmer</job>
<department>Technical Support</department>
<cubicle>19T</cubicle>
</employee>
</employees>
Guys ifsome onecan help pleassssssssseeeee! i really need tofix this
cheers
jiggs
Charles
04-29-2003, 03:40 PM
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
encoding="iso-8859-1"
indent="yes"
method="xml"
version="1.1"/>
<xsl:template match="employees">
<xsl:apply-templates select="employee">
<xsl:sort select="name"/>
</xsl:apply-templates>
</xsl:template>
<xsl:template match="employee[name/text() = 'Name']"/>
<xsl:template match="employee">
<dl>
<xsl:apply-templates/>
</dl>
</xsl:template>
<xsl:template match="name">
<dt>
<xsl:apply-templates/>
</dt>
</xsl:template>
<xsl:template match="job | department | cubicle">
<dd>
<xsl:apply-templates/>
</dd>
</xsl:template>
</xsl:stylesheet>
jiggs
04-29-2003, 04:57 PM
thanks for that charles, thats great however i cant see the file when i turnthe code into a html document and viewit throughmy browser?
is there sumthin im doin wrong? or am i notmeant to see anything?
cheers mate
sorry bout this but im a major xml newbie
khalidali63
04-29-2003, 05:20 PM
Charles code works.You did not mention how are you trying to view the results,
You may have 2 options
1. view the xml in browser using default XSL/XSLT parsers
2. use a stand alone XSL/XSLT parser e.g xalan....
The easier option will be to use browsers built in parser (both NS6+ and IE6+ do have their built in xsl parser).
Here is what you need to do for viewing this XML file in a browser.
Save both XML and XSL files in the same folder.
in the xml file right below the XML declaration (<?xml version="1.0"?>)
paste this line
<?xml-stylesheet href="jiggs.xsl" type="text/xsl" encoding="ISO-8859-1"?>
Now save Charles posted XSL code in a file and name it "jiggs.xsl" for this examples sake.
Make sure that both files have their appropriate file extensions.( .xml and .xsl)
Once this is done open the XML file with NS6+ or IE6+ browsers..
Charles
04-29-2003, 05:30 PM
I generally use Saxon as my XSLT processor. http://saxon.sourceforge.net/
jiggs
04-29-2003, 05:47 PM
thanks alot you guys you are an excellent help and i appreciate it so much.
i will work on that tonight and get back to you tomorrow should i have further problems.
is that ok?
I hope u guys will still be here lol i will probably need more help!!!!
im glad i found this place!
cheers again
sean
(terrible programmer-still learning)
khalidali63
04-29-2003, 05:57 PM
Originally posted by jiggs
........
I hope u guys will still be here lol i will probably need more help!!!!
Don't worry...we'll be here..:D
NOTE:
Glad to see that charles is another person here who can help this forum..
Hey Charles do you still program in xsl/xslt??
I used to be a frequent user of mullberry's the BIG LIST forum...(few yrs back..:D )
Charles
04-29-2003, 06:22 PM
At this very moment I'm tearing out my hair over an XSLT project in another window.
It's a most pecular problem and it's a little something I tossed together for my wife. She marked up the XML and then sent me the files by e-mail. I cannot see anything wrong but it keeps flagging an error at the first entity with the message "End tag was not expected at this location." I think it has something to do with the encoding and new line characters.
khalidali63
04-29-2003, 06:30 PM
My knowledgeis rusty(have not used it for 3 yrs at least) for XSL when it comes to extreme logic intentsive code...but you can email me (xml and XSL)to take a look...may be its something very simple which you can not see at this time..
k_ali@shaw.ca
sheila
04-29-2003, 07:14 PM
Just out of curiousity, is there a difference between these two statements?
1. <xsl:template match="employee[name/text() = 'Name']"/>
2. <xsl:template match="employee[name]" />
Charles
04-29-2003, 08:15 PM
Khalid, thanks. But I think that I need to start by walking the files home on a disk. I've noticed before that Outlook Express changes files.
sheila, Apart <xsl:template match="employee[name/text() = 'Name']"/>matches all 'employee' elements that contain a 'name' element that contains the text 'Name' while <xsl:template match="employee[name]" /> matches all 'employee' elements. Taken together, the most specific match wins.
sheila
04-30-2003, 03:27 PM
Sorry, I should have been able to work that out for myself! But to continue picking your expert brain...
I would normally write that as:
<xsl:template match="employee[name='Name']" />
Is this wrong/inadvisable?