www.webdeveloper.com
Results 1 to 12 of 12

Thread: xslt

  1. #1
    Join Date
    Apr 2003
    Posts
    3

    Unhappy xslt

    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

  2. #2
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    Code:
    <?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>
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  3. #3
    Join Date
    Apr 2003
    Posts
    3

    Cheers charles

    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

  4. #4
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    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..

  5. #5
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    I generally use Saxon as my XSLT processor. http://saxon.sourceforge.net/
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  6. #6
    Join Date
    Apr 2003
    Posts
    3

    cheers to both you guys

    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)

  7. #7
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653

    Re: cheers to both you guys

    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..

    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.. )

  8. #8
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    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.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  9. #9
    Join Date
    Dec 2002
    Location
    Calgary, Canada
    Posts
    2,653
    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

  10. #10
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    95
    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]" />

  11. #11
    Join Date
    Nov 2002
    Location
    Baltimore, Maryland
    Posts
    12,279
    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.
    “The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect.”
    —Tim Berners-Lee, W3C Director and inventor of the World Wide Web

  12. #12
    Join Date
    Apr 2003
    Location
    London, UK
    Posts
    95
    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?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles