XML XSL javascript, sorting child node of data island

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim

    XML XSL javascript, sorting child node of data island

    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">&nbsp;</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----
  • Andy Dingley

    #2
    Re: XML XSL javascript, sorting child node of data island

    On 18 Feb 2004 14:08:06 -0800, smithco1@hotmai l.com (Tim) wrote:
    [color=blue]
    >I've been working on this for over a week now,[/color]

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

    --
    Smert' spamionam

    Comment

    • Tim

      #3
      Re: XML XSL javascript, sorting child node of data island

      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.
      [color=blue]
      > 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).[/color]

      Comment

      • Andy Dingley

        #4
        Re: XML XSL javascript, sorting child node of data island

        On 19 Feb 2004 08:03:44 -0800, smithco1@hotmai l.com (Tim) wrote:
        [color=blue]
        >Can you recomend any sites that have good tutorials on this kind of
        >thing?[/color]

        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
        --
        Smert' spamionam

        Comment

        • Tim

          #5
          Re: XML XSL javascript, sorting child node of data island

          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!
          [color=blue][color=green]
          > >Can you recomend any sites that have good tutorials on this kind of
          > >thing?[/color]
          >
          > 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[/color]

          Comment

          • Thomas 'PointedEars' Lahn

            #6
            Re: XML XSL javascript, sorting child node of data island

            Andy Dingley wrote:
            [color=blue]
            > 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 ?
            > [...][/color]

            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.helpscribbl e.com/decompiler.html >
            <http://msdn.microsoft. com/workshop/author/htmlhelp/download.asp>
            <http://www.keyworks.ne t/>
            <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.e xe
            $hlp_file" with it: <http://www.codeweavers .com/products/crossover/>


            F'up2 comp.text.xml

            PointedEars

            Comment

            Working...