General discussion

Locked

XML QUESTION

By elrey103 ·
My friend is looking for how to do something in XML - here's what he wrote......
he knows XML fairly well - but can't figure out for the life of him how to get it to ALPHABITZE the stuff...
There are lots of tutorials and stuff that assume he knows too much already apparently....
Please write a complete script that will pull the data from the following XML database and list the names in alphabetical order and display it on a webpage


<company>
<employee>
<name>Ed</name>
</employee>
<employee>
<name>Jeremy</name>
</employee>
<employee>
<name>Frank</name>
</employee>
</company>

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

by pryzhkov In reply to XML QUESTION

You should use <xsl:sort> element within <xsl:apply-templates> or <xsl:for-each> element to reorganize existing XML file for future processing. The stylesheet should include something like:

...
<xsl:for-each select="name">
<xsl:sort select="."/>
<xsl:value-of select="."/>
</xsl:for-each>
...

Collapse -

by chellaganesh In reply to XML QUESTION

Here is an easy example for you:

-------------------------- XML
<?xml version="1.0" encoding="ISO-8859-1"?>
<company>
<employee>
<title>Cars</title>
<artist>Ed</artist>
</employee>
<employee>
<title>Bikes</title>
<artist>Jeremy</artist>
</employee>
<employee>
<title>Trucks</title>
<artist>Frank</artist>
</employee>
</company>
save this as cdcatalog.xml
-------------------------------------
<?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>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="company/employee">
<xsl:sort select="./title"/>
<tr>
<td><xsl:value-of select="title" /></td>
<td><xsl:value-of select="artist" /></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template></xsl:stylesheet>
save this as Xsl cdcatalog.xsl
-------------------------------------
<html>
<body><script type="text/javascript">// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("cdcatalog.xml")// Load XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("cdcatalog.xsl")// Transform
document.write(xml.transformNode(xsl))</script></body>
</html>

save this as master.html and open this in browser
You will get the list sorted on title

Back to Web Development Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums