XML XSL javascript, sorting child node of data island

T

Tim

I've been working on this for over a week now, and just can't get this
figured out. Hoping one of you gurus can help me out here.

I have an xml data island that I'm representing on an htm page as an
expandable menu. Got that working, but now I need to add sorting and
searching abilities to the menu. I am hoping to do this with xsl but
can't get it to work.

Is this because of the way I've formed my xml, having the children
within the parent elements? Or is my xml alright but my xsl is mis
formed.

If you could help me figure out how to simply have xsl sort the list,
I'm sure I could figure out the rest.

If your solution is strictly using javascript, then please be specific
as I'm not too familiar with the javascript/xml api yet.

----html code below----

<XML id=xmlDSO></XML>
<XML ID="SortDateXSL">
<root>
<xsl:for-each order-by="+ item_title" select="root/master/detail"
xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<master>
<category_id><xsl:value-of select="category_id"/></category_id>
<category_name><xsl:value-of
select="category_name"/></category_name>
<detail>
<item_id><xsl:value-of select="item_id"/></item_id>
<item_title><xsl:value-of select="item_title"/></item_title>
<item_date><xsl:value-of select="item_date"/></item_date>
<item_hours><xsl:value-of select="item_hours"/></item_hours>
<item_posted><xsl:value-of select="item_posted"/></item_posted>
</detail>
</master>
</xsl:for-each>
</root>
</XML>

<XML ID="SortTitleXSL">
<root>
<master>
<category_id><xsl:value-of select="category_id"/></category_id>
<category_name><xsl:value-of
select="category_name"/></category_name>
<xsl:for-each order-by="+ item_title" select="master"
xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<detail>
<xsl:attribute name="ID"><xsl:value-of select="@ID"/>
<item_id><xsl:value-of select="item_id"/></item_id>
<item_title><xsl:value-of select="item_title"/></item_title>
<item_date><xsl:value-of select="item_date"/></item_date>
<item_hours><xsl:value-of select="item_hours"/></item_hours>
<item_posted><xsl:value-of select="item_posted"/></item_posted>
</detail>
</xsl:for-each>
</master>
</root>
</XML>

<TABLE dataSrc="#xmlDSO" cellSpacing="0" cellPadding="0">
<TBODY>
<TR>
<TD colSpan="2">
<TABLE style="FONT-SIZE: 12px; FONT-FAMILY: arial; TEXT-ALIGN: left"
cellSpacing="0" cellPadding="0">
<TBODY>
<TR>
<TD style="WIDTH: 20px; HEIGHT: 20px" align="right">
<IMG style="CURSOR: hand" onclick="doExpandClick(tblDetails);"
src="img/xml-plus.gif" align=absMiddle>
</TD>
<TD style="WIDTH: 20px; HEIGHT: 20px">
<IMG src="img/xml-folder.gif">
</TD>
<TD style="WIDTH: 500px; TEXT-ALIGN: left">
<SPAN DATAFLD="category_name"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD style="WIDTH: 20px"></TD>
<TD>
<TABLE dataFld="detail" style="DISPLAY: none" dataSrc="#xmlDSO"
cellSpacing="1" cellPadding="2" border="0">
<THEAD>
<TR>
<TH style="WIDTH: 20px">&nbsp;</TH>
<TH style="WIDTH: 400px" align="middle">
<NOBR><A href="javascript:sort(SortTitleXSL.XMLDocument)">Title</A></NOBR>
</TH>
<TH style="WIDTH: 50px" align="middle">
<NOBR><A href="javascript:sort(SortDateXSL.XMLDocument)">Year</A></NOBR>
</TH>
<TH style="WIDTH: 50px" align="middle">
<NOBR>Hours</NOBR>
</TH>
<TH style="WIDTH: 50px" align="middle">
<NOBR>Posted</NOBR>
</TH>
</TR>
</THEAD>
<TBODY>
<TR id="trDetail" name="trDetail">
<TD style="WIDTH: 20px">
<IMG src="img/xml-item.gif">
</TD>
<TD style="WIDTH: 400px" align="left">
<SPAN DATAFLD="item_title"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_date"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_hours"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_posted"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>

<SCRIPT language=javascript>
xmlDSO.async = false;
xmlDSO.load("test_tool_get-xml.xml");
var xmldoc = xmlDSO.cloneNode(true);

function sort(WhichXSL){
xmlDSO.loadXML(xmldoc.documentElement.transformNode
(WhichXSL.documentElement));
}

function doExpandClick(tblDetailData){
try{
var strSrc = new String(event.srcElement.src);
if (strSrc.indexOf("minus") > 0){
strNewSrc = strSrc.replace("minus", "plus");
}
else{
strNewSrc = strSrc.replace("plus", "minus");
}
event.srcElement.src = strNewSrc
var recNumber = event.srcElement.recordNumber - 1;
if (tblDetailData[recNumber].style.display == "none"){
tblDetailData[recNumber].style.display = "";
}
else{
tblDetailData[recNumber].style.display = "none";
}
}
}
</SCRIPT>


----end html----
################
----xml file below saved as "test_tool_get-xml.xml"----


<?xml version="1.0" ?>
<root>
<master id="3">
<category_id>3</category_id>
<category_name>Cosourcing</category_name>
</master>
<master id="2">
<category_id>2</category_id>
<category_name>Comprehensive Tax Solutions</category_name>
</master>
<master id="1">
<category_id>1</category_id>
<category_name>Business Advisory</category_name>
</master>
<master id="4">
<category_id>4</category_id>
<category_name>GEIS--EBT</category_name>
<detail id="34">
<item_id>34</item_id>
<item_title>G Time! Executive Compensation</item_title>
<item_date>2003</item_date>
<item_hours>1</item_hours>
<item_href></item_href>
<item_src></item_src>
<item_type>xml-item</item_type>
<item_posted></item_posted>
</detail>
<detail id="77">
<item_id>77</item_id>
<item_title>Family Wealth Planning Basis Estate Planning (1 of
6)</item_title>
<item_date>2003</item_date>
<item_hours>2</item_hours>
<item_href></item_href>
<item_src></item_src>
<item_type>xml-item</item_type>
<item_posted></item_posted>
</detail>
<detail id="80">
<item_id>80</item_id>
<item_title>Employee Benefits Update</item_title>
<item_date>2003</item_date>
<item_hours>0.5</item_hours>
<item_href></item_href>
<item_src></item_src>
<item_type>xml-item</item_type>
<item_posted></item_posted>
</detail>
</master>
<master id="5">
<category_id>5</category_id>
<category_name>GEIS--IAS</category_name>
</master>

</root>


----end xml----
 
A

Andy Dingley

I've been working on this for over a week now,

Yes, well take whatever obsolete book you're reading and throw it a
very long way away. Nothing that contains the strings "DSO" or the
attribute "dataFld" has ever worked right.

Use client-side XSLT. It's a bit browser-specific, but it does work
well (where it can work at all).
 
T

Tim

Okay, thanks for the advice.

Can you recomend any sites that have good tutorials on this kind of
thing?

Everything I know comes from googling but I'm afraid I might be asking
google the wrong questions.
 
A

Andy Dingley

Can you recomend any sites that have good tutorials on this kind of
thing?

Sorry, no. I'm sure there are, but I'm not up to date on what's out
there.

As to books, then my tutorial pick is still Michael Kay's XSLT book.
That'll cover XSLT and XPath, and the client-side scripting for data
islands is a trivial example that's a M$oft example (you load the
document into one DOM, the XSLT into another and use the
..transformNode() method)..

M$oft do a very useful (and a free download) SDK for their MSXML
component. This is a Windows help file that describes XSLT and DOM.
It's thin on examples, terrible as a tutorial, but a convenient
reference that I never travel without.

BTW - Is there any way to use this thing on a Linux box ? WINE ? It's
cross-language, so the JavaScript version of it is also a pretty
useful reference for accessing DOM from Java
 
T

Tim

May thanks.
I've got this thing working as a straight xml page now while using xsl
to format it. I can see the light!

Now all I have to do is import the menu into an asp page from the
client. I guess it's the same as importing the xml into an html page.
Time to go script searching...

Will look into your tut' samples once I get some more time.

BTW, I tried running this MS help file in cygwin, but no fun. I didn't
try too hard though.
If you wanted to run this in *nix I woud suggest finding a Linux
version of a .chm reader. The file you want to read is the help file
in the MSXML 4.0 folder in your program files folder. I have no idea
if there is such a thing for *nix but I'm sure there is, so good luck.

Thanks again!
 
T

Thomas 'PointedEars' Lahn

Andy said:
M$oft do a very useful (and a free download) SDK for their MSXML
component. This is a Windows help file that describes XSLT and DOM.
It's thin on examples, terrible as a tutorial, but a convenient
reference that I never travel without.

BTW - Is there any way to use this thing on a Linux box ? WINE ?
[...]

I do not know what type of file you are exactly writing about. However,
you can decompile Help files (.hlp) or compiled HTML files (.chm) and
then view it on Linux with your favorite app. From a Google search for
"decompile html help":

<http://www.helpscribble.com/decompiler.html>
<http://msdn.microsoft.com/workshop/author/htmlhelp/download.asp>
<http://www.keyworks.net/>
<http://www.blue-sky.com/>

If you need only one compiled HTML document, you can view the source
in your favorite text editor (right-click, View Source) and save it
whereever you want.

The CrossOver Plugin (includes a basic WINE distribution) *could*
be another possibility, run "hh.exe $chm_helpfile" or "winhlp32.exe
$hlp_file" with it: <http://www.codeweavers.com/products/crossover/>


F'up2 comp.text.xml

PointedEars
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,771
Messages
2,569,587
Members
45,099
Latest member
AmbrosePri
Top