XML, XSL, HTML help

jtvang125

Diamond Member
Nov 10, 2004
5,399
51
91
Ok I downloaded this free app that converts a XML file into a XHTML file viewable in a web broswer. Well the XML file I need help on is from my movie database. At the moment the app is listing all the movies by the ID number. However I want it to sort by the name of the movie in alphabetical order. I know little to no programming but maybe someone here can help me. I have pasted the contents of the app files. One is a vbs script file and a xsl file. I'm assuming you just have to input a sort command in one of the files at the right syntax. Thanks in advance.

XML to HTML.vbs
-------------------------------
Dim xslDoc, xmlDoc, fileSystem, file, sOutput

Set xslDoc = CreateObject ("MSXML2.DOMDocument")
Set xmlDoc = CreateObject ("MSXML2.DOMDocument")
Set fileSystem = CreateObject("Scripting.FileSystemObject")


xslDoc.async = False
xslDoc.Load ".\simple-report.xsl"
'xslDoc.Load ".\front-contactsheet-report.xsl"
'xslDoc.Load ".\detailed-report.xsl"
If (xslDoc.parseError.errorCode <> 0) Then
Dim myErr
Set myErr = xslDoc.parseError
WScript.Echo "Stylesheet error: " + myErr.reason
Else
xmlDoc.async = False
xmlDoc.Load ".\MMDB.xml"
If (xmlDoc.parseError.errorCode <> 0) Then
Set myErr = xmlDoc.parseError
WScript.Echo "XML document error: " + myErr.reason
Else
sOutput = xmlDoc.transformNode(xslDoc)

Set file = fileSystem.CreateTextFile("report.xhtml")
file.write sOutput
file.Close
End If
End If



simple-report.xsl
---------------------------------------
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:eek:utput method="xml"
media-type="text/html"
version="1.1"
doctype-public="-//W3C//DTD XHTML 1.1//EN"
doctype-system="http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"
encoding="UTF-8"
standalone="no"
omit-xml-declaration="no"
indent="yes"/>

<!-- Page configuration variables -->
<xsl:variable name="cellsPerRow" select="2"/>

<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml"
xml:lang="en">
<head>
<title>My Movies - Simple Report</title>
</head>
<body id="body">
<table width="760px">
<tr style="font-weight: bold;">
<td width="2%">ID</td>
<td width="6%">Prod. Year</td>
<td width="42%">Title</td>
<td width="2%">ID</td>
<td width="6%">Prod. Year</td>
<td width="42%">Title</td>
</tr>
<xsl:apply-templates select="Titles" />

</table>
</body>
</html>
</xsl:template>


<!-- Build Movie List Rows -->
<xsl:template match="Titles">
<xsl:for-each select="Title[position() mod $cellsPerRow = 1]">
<tr xmlns="http://www.w3.org/1999/xhtml">
<xsl:apply-templates
select=".|following-sibling::Title[position() < $cellsPerRow]"/>
</tr>
</xsl:for-each>
</xsl:template>

<xsl:template match="Title">
<td xmlns="http://www.w3.org/1999/xhtml">
<xsl:value-of select="CollectionNumber"/>
</td>
<td xmlns="http://www.w3.org/1999/xhtml">
<xsl:if test="ProductionYear > 0">
<xsl:value-of select="ProductionYear"/>
</xsl:if>
</td>
<td xmlns="http://www.w3.org/1999/xhtml">
<xsl:value-of select="LocalTitle"/>

</td>

</xsl:template>

</xsl:stylesheet>
 

MrChad

Lifer
Aug 22, 2001
13,507
3
81
After this line

<xsl:for-each select="Title[position() mod $cellsPerRow = 1]">

add

<xsl:sort select="Title"/>
 

Ken g6

Programming Moderator, Elite Member
Moderator
Dec 11, 1999
16,838
4,817
75
It appears to be just what jtvang125 pasted into his post: those two files. Of course, you have to modify them (well, mainly the XSL file) for your specific XML and HTML needs.

I'm guessing you'll next want to learn about the XSL language.