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><x sl:value-of select="categor y_id"/></category_id>
<category_name> <xsl:value-of
select="categor y_name"/></category_name>
<detail>
<item_id><xsl:v alue-of select="item_id "/></item_id>
<item_title><xs l:value-of select="item_ti tle"/></item_title>
<item_date><xsl :value-of select="item_da te"/></item_date>
<item_hours><xs l:value-of select="item_ho urs"/></item_hours>
<item_posted><x sl:value-of select="item_po sted"/></item_posted>
</detail>
</master>
</xsl:for-each>
</root>
</XML>
<XML ID="SortTitleXS L">
<root>
<master>
<category_id><x sl:value-of select="categor y_id"/></category_id>
<category_name> <xsl:value-of
select="categor y_name"/></category_name>
<xsl:for-each order-by="+ item_title" select="master"
xmlns:xsl="http ://www.w3.org/TR/WD-xsl">
<detail>
<xsl:attribut e name="ID"><xsl: value-of select="@ID"/>
<item_id><xsl:v alue-of select="item_id "/></item_id>
<item_title><xs l:value-of select="item_ti tle"/></item_title>
<item_date><xsl :value-of select="item_da te"/></item_date>
<item_hours><xs l:value-of select="item_ho urs"/></item_hours>
<item_posted><x sl:value-of select="item_po sted"/></item_posted>
</detail>
</xsl:for-each>
</master>
</root>
</XML>
<TABLE dataSrc="#xmlDS O" 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="doExpa ndClick(tblDeta ils);"
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="catego ry_name"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD style="WIDTH: 20px"></TD>
<TD>
<TABLE dataFld="detail " style="DISPLAY: none" dataSrc="#xmlDS O"
cellSpacing="1" cellPadding="2" border="0">
<THEAD>
<TR>
<TH style="WIDTH: 20px"> </TH>
<TH style="WIDTH: 400px" align="middle">
<NOBR><A href="javascrip t:sort(SortTitl eXSL.XMLDocumen t)">Title</A></NOBR>
</TH>
<TH style="WIDTH: 50px" align="middle">
<NOBR><A href="javascrip t:sort(SortDate XSL.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_t itle"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_d ate"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_h ours"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_p osted"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT language=javasc ript>
xmlDSO.async = false;
xmlDSO.load("te st_tool_get-xml.xml");
var xmldoc = xmlDSO.cloneNod e(true);
function sort(WhichXSL){
xmlDSO.loadXML( xmldoc.document Element.transfo rmNode
(WhichXSL.docum entElement));
}
function doExpandClick(t blDetailData){
try{
var strSrc = new String(event.sr cElement.src);
if (strSrc.indexOf ("minus") > 0){
strNewSrc = strSrc.replace( "minus", "plus");
}
else{
strNewSrc = strSrc.replace( "plus", "minus");
}
event.srcElemen t.src = strNewSrc
var recNumber = event.srcElemen t.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>xm l-item</item_type>
<item_posted> </item_posted>
</detail>
<detail id="77">
<item_id>77</item_id>
<item_title>Fam ily 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>xm l-item</item_type>
<item_posted> </item_posted>
</detail>
<detail id="80">
<item_id>80</item_id>
<item_title>Emp loyee 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>xm l-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----
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><x sl:value-of select="categor y_id"/></category_id>
<category_name> <xsl:value-of
select="categor y_name"/></category_name>
<detail>
<item_id><xsl:v alue-of select="item_id "/></item_id>
<item_title><xs l:value-of select="item_ti tle"/></item_title>
<item_date><xsl :value-of select="item_da te"/></item_date>
<item_hours><xs l:value-of select="item_ho urs"/></item_hours>
<item_posted><x sl:value-of select="item_po sted"/></item_posted>
</detail>
</master>
</xsl:for-each>
</root>
</XML>
<XML ID="SortTitleXS L">
<root>
<master>
<category_id><x sl:value-of select="categor y_id"/></category_id>
<category_name> <xsl:value-of
select="categor y_name"/></category_name>
<xsl:for-each order-by="+ item_title" select="master"
xmlns:xsl="http ://www.w3.org/TR/WD-xsl">
<detail>
<xsl:attribut e name="ID"><xsl: value-of select="@ID"/>
<item_id><xsl:v alue-of select="item_id "/></item_id>
<item_title><xs l:value-of select="item_ti tle"/></item_title>
<item_date><xsl :value-of select="item_da te"/></item_date>
<item_hours><xs l:value-of select="item_ho urs"/></item_hours>
<item_posted><x sl:value-of select="item_po sted"/></item_posted>
</detail>
</xsl:for-each>
</master>
</root>
</XML>
<TABLE dataSrc="#xmlDS O" 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="doExpa ndClick(tblDeta ils);"
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="catego ry_name"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
<TR>
<TD style="WIDTH: 20px"></TD>
<TD>
<TABLE dataFld="detail " style="DISPLAY: none" dataSrc="#xmlDS O"
cellSpacing="1" cellPadding="2" border="0">
<THEAD>
<TR>
<TH style="WIDTH: 20px"> </TH>
<TH style="WIDTH: 400px" align="middle">
<NOBR><A href="javascrip t:sort(SortTitl eXSL.XMLDocumen t)">Title</A></NOBR>
</TH>
<TH style="WIDTH: 50px" align="middle">
<NOBR><A href="javascrip t:sort(SortDate XSL.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_t itle"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_d ate"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_h ours"></SPAN>
</TD>
<TD style="WIDTH: 50px" align="middle">
<SPAN DATAFLD="item_p osted"></SPAN>
</TD>
</TR>
</TBODY>
</TABLE>
</TD>
</TR>
</TBODY>
</TABLE>
<SCRIPT language=javasc ript>
xmlDSO.async = false;
xmlDSO.load("te st_tool_get-xml.xml");
var xmldoc = xmlDSO.cloneNod e(true);
function sort(WhichXSL){
xmlDSO.loadXML( xmldoc.document Element.transfo rmNode
(WhichXSL.docum entElement));
}
function doExpandClick(t blDetailData){
try{
var strSrc = new String(event.sr cElement.src);
if (strSrc.indexOf ("minus") > 0){
strNewSrc = strSrc.replace( "minus", "plus");
}
else{
strNewSrc = strSrc.replace( "plus", "minus");
}
event.srcElemen t.src = strNewSrc
var recNumber = event.srcElemen t.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>xm l-item</item_type>
<item_posted> </item_posted>
</detail>
<detail id="77">
<item_id>77</item_id>
<item_title>Fam ily 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>xm l-item</item_type>
<item_posted> </item_posted>
</detail>
<detail id="80">
<item_id>80</item_id>
<item_title>Emp loyee 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>xm l-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----
Comment