Re: [xsl] Filtering XML with XSL

Subject: Re: [xsl] Filtering XML with XSL
From: "Charles White" <chuck@xxxxxxxxxxx>
Date: Wed, 5 Feb 2003 17:13:05 -0800
Can you post the code that is failing? Generally (not always), when using
the XMLDocument and XSLDocument properties client-side, you are using them
to reload the XSLT so that you can do things like feed new parameter values
and the like upon reload.

Chuck White
Author, Mastering XSLT, Sybex Books
http://www.javertising.com/webtech
http://www.tumeric.net

----- Original Message -----
From: "Sam Awad" <sammy_awad@xxxxxxxxx>
To: <xsl-list@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Wednesday, February 05, 2003 3:49 PM
Subject: RE: [xsl] Filtering XML with XSL


> Thanks Steve for your help. My xml is dynamically created and it seems to
me
> like you are doing a server side trip to retransform.
> At this point, my problem is that the javascript does not work with the
> properties XMLDocument and XSLDocument. They don't work with the DOM
object
> or the navigator object. I got alerts all over the script and the
following
> variables come up undefined:
> - document.XMLDocument
> - navigator.XMLDocument
>
> Not sure what the pre-requisites for Chris Bayes's javascript are. I am
> running IE6 on a w2k sp2 ==> my msxml is version 3 running in "replace
> mode".
>
> I really hope that someone on the list has any ideas as to what is
happening
> here.
>
> Thanks in advance to anyone for any help.
>
>
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Steve Gold
> Sent: Monday, February 03, 2003 8:16 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Filtering XML with XSL
>
>
> The code I use follows.  One quick comment though, while the
> transformation is happening "client-side" because it is in the browser,
> I am pretty sure you can't do this as an OnClick event and change what
> is depicted in the browser.  It's not that kind of client-side.  It acts
> almost as though the Active-X call is happening pseudo-server-side
> because it pretty much gices you a static HTML-like page.  I don't know
> of a way to change what is displayed on the screen via XML without
> making another request albeit a client-side one. Does that make sense to
> you?  In other words, if you give them values in a drop-down box and
> they select an item, you have to call the page again, passing in that
> new value via the URL, and then filter it using the add parameter and
> requery the XML file.
>
> Anyway, the code looks similar to what you have below.  Here goes:
>
> 1. This is the HTML page which is called as
> "mypage.htm?year_to_show=2002"  The JavaScript file referenced in the
> first line is shown below as item #2.
> <script language="JavaScript" src="../JS_Code/xml.js">
> </script>
> <script language="JavaScript">
> // REDIRECT IF USING NON-XML BROWSER
>
> func_shared_browser_www("../ASP_Transform/Training_schedule_menu_month_t
> ransform.asp");
>
> // GET THE SEARCH STRING OR THE URL
> var search_string = location.search;
>
>
> ////////////////////////////////////////////////////////////////////////
> ///////////////////////////////////
> //////////// RESET THE CODE BELOW AS NEEDED TO READ VALUES
> FROM INCOMING FIELDS //////////////////
>
> ////////////////////////////////////////////////////////////////////////
> /////////////////////////////////
>
> // GET DEFAULT VALUE FOR THE YEAR
> temp = new Date();
> temp_year = temp.getYear();
> // IDENTIFY THE YEAR
> parm_name[num_of_parms] = "year_to_show";
> parm_value[num_of_parms] = func_get_field_value(temp_year,
> "year_to_show", search_string, "","","","","","");
> num_of_parms = num_of_parms + 1;
>
>
> ////////////////////////////////////////////////////////////////////////
> ///////////////////////////////////
> //////////// SET THE XML AND XSL PAGES AND DO THE
> TRANSFORMATION //////////////////
>
> ////////////////////////////////////////////////////////////////////////
> ///////////////////////////////////
> // SET THE XML DATA PAGE
> var xml_source =
> "../XML_Data/Training_Schedules/training_schedule_data.xml";
> // SET THE XSL FORMAT PAGE
> var xsl_format =
> "../XSL_Format/training_schedule_menu_month_format.xsl";
> // EXECUTE THE TRANSFORMATION
> func_JS_Transform(xsl_format, xml_source, num_of_parms, "", "",
> "", "", "", "");
> </script>
>
>
>
>
>
>
>
>
>
>
>
> 2. The xml.js file shown below, is included in all the HTM pages.
> It allows for quick parsing of the URL and a shared way to do the
> transformation.  (Handy if that method ever changes- just change one
> file.)  This will not let them proceed without IE version 5 or above.
> // SET THE NUMBER OF PARAMETERS
> // MUST ALWAYS BE ONE OR GREATER
> var num_of_parms = 1;
>
> // DECLARE THE PARAMETER ARRAYS
> var parm_name = new Array;
> var parm_value = new Array;
> // SET THE FIRST PARAM
> // PARAM 0 MUST ALWAYS INDICATE ASP OR HTML TRANSFORM
> parm_name[0] = "href_type";
> parm_value[0] = "HTM";
>
> // REDIRECT
> function func_shared_browser_www(URL_value) {
> browser = (((navigator.appName == "Microsoft Internet
> Explorer") &&
> (parseInt(navigator.appVersion) < 5 )))
>
> temp_loc = location;
> temp_loc2 = temp_loc + "";
> temp_test = temp_loc2.substring(0,7).toUpperCase();
> if (browser) {
> // USING IE > 4
> // ON THE WEB
> // USE THE ASP VERSION UNTIL THE HTML IS
> ALL DONE
> if(temp_test == "HTTP://";) {
> temp = URL_value + location.search;
> location.href = temp;
> }
> }
> else {
> // NOT USING IE > 4
> if(temp_test == "HTTP://";) {
> // ON THE WEB
> temp = URL_value + location.search;
> location.href = temp;
> }
> else {
> // NOT ON THE WEB
> temp = "You are using a browser that is
> not supported by this application.";
> temp = temp + "\n\nTo run this
> application offline, you need to use Internet Explorer (version 4 or
> greater)";
> temp = temp + "\n\nOr visit our website
> at http://www.yoursite.com";;
> alert(temp);
> document.writeln('<br /><br /><b><pre>'
> + temp + '</pre></b>');
> }
> }
> }
>
>
>
> // GET FIELD VALUE OF AN ITEM FROM THE LOCATION.SEARCH
> OBJECT IN THE URL
> function func_get_field_value(default_value, field_name,
> incoming_string, future1, future2, future3, future4, future5, future6) {
> // DOES THE STRING CONTAIN & AT ALL?
> qpos = incoming_string.indexOf("&");
> var outgoing = default_value;
> // CHECK TO SEE HOW MANY FIELDS THERE ARE
> if(incoming_string.length > 0) {
> incoming = incoming_string.toLowerCase();
> if(qpos == -1) {
> // SINGLE INCOMING FIELD
>
> if(incoming.substring(1,field_name.length + 1) == field_name) {
> outgoing =
> (incoming_string.substring((field_name.length +
> 2),incoming_string.length));
> }
> }
> else {
> // MULTIPLE INCOMING FIELDS
> // SEE IF THE FIELD IS THE FIRST IN
> THE LIST
> if(incoming.substring(0,
> (field_name.length + 2)) == ("?" + field_name + "=")) {
> outgoing =
> (incoming_string.substring((field_name.length +
> 2),incoming_string.indexOf("&")));
> }
> else {
> if(incoming.indexOf(("&" +
> field_name + "=")) > 0) {
> field_start =
> (incoming.indexOf(("&" + field_name + "=")) + (field_name.length + 2));
> field_end =
> (incoming.indexOf("&", field_start + 1));
> if(field_end == -1) {
> field_end =
> incoming.length;
> }
> // LOCATE THE FIELD
> IN THE LIST
> outgoing =
> incoming_string.substring(field_start, field_end);
> }
> }
> }
> }
> return outgoing;
> }
>
> // DO THE TRANSFORMATION
> function func_JS_Transform(
> xsl_doc
> , xml_doc
> , num_of_parms
> , future1
> , future2
> , future3
> , future4
> , future5
> , future6
> ) {
> var xslt = new ActiveXObject("Msxml2.XSLTemplate");
> var xslDoc = new
> ActiveXObject("Msxml2.FreeThreadedDOMDocument");
> var xslProc;
> xslDoc.async = false;
> xslDoc.resolveExternals = false;
>
> // LOAD THE XSL FORMAT PAGE
> xslDoc.load(xsl_doc);
> xslt.stylesheet = xslDoc;
>
> var xmlDoc = new ActiveXObject("Msxml2.DOMDocument");
> xmlDoc.async = false;
> xmlDoc.resolveExternals = false;
>
> // LOAD THE XML DATA PAGE
> xmlDoc.load(xml_doc);
> xslProc = xslt.createProcessor();
> xslProc.input = xmlDoc;
>
> // ADD PARAMETERS
> for(i = 0; i < num_of_parms; i++) {
> //alert(parm_name[i] + " = " + parm_value[i]);
> xslProc.addParameter(parm_name[i],
> parm_value[i]);
> }
> xslProc.addParameter("xml_source", xml_doc);
> xslProc.addParameter("xsl_format", xsl_doc);
>
> // TRANSFORM THE DOCUMENT
> xslProc.transform();
> document.write(xslProc.output);
> }
>
>
>
>
>
>
>
> 3. The XSL starts out like this:
> <?xml version="1.0" encoding='ISO-8859-1'?>
> <xsl:stylesheet version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> <xsl:import href="constants_format.xsl" />
> <xsl:import href="shared_agenda_format.xsl" />
> <xsl:param name="href_type" />
> <xsl:param name="browser" select="'NOT_IE'" />
> <xsl:param name="year_to_show" />
> ......................
>
>  And eventually does:         <xsl:for-each
> select="ROWSET/ROW/COURSE[YEAR = $year_to_show .......
> Which does the filtering in XSL.
>
>
>
>
>
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Sam Awad
> Sent: Monday, February 03, 2003 3:55 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Filtering XML with XSL
>
>
> XMLDocument is a class. The code below is a function I call within an
> XSL file via an 'OnClick' event handler on a column heading. The
> JavaScript should edit the xml loaded in the object. Hope I answered
> your question. Thanks. -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Alan Flaherty
> Sent: Monday, February 03, 2003 12:57 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Filtering XML with XSL
>
>
> Hi there,
>
> If this data is being displayed in a table why not use the
> TabularDataControl to display and filter the data, this has a set of
> inbuilt methods for filtering and sorting the data, its quite simple to
> use.
>
> http://msdn.microsoft.com/workshop/database/tdc/reference/filter.asp
>
> The TDC methods are very much like standard ado methods on a recordset
> so they should look familiar.
>
> With regards the code below, is there a XML dataIsland on the page
> called XMLDocument with a XSL Stylesheet inside it??, this xsl file will
> need to be customised to your own needs.
>
>
>
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of Sam Awad
> Sent: 03 February 2003 16:38
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Cc: Steve@xxxxxxxxxxxxx
> Subject: RE: [xsl] Filtering XML with XSL
>
> Hi Steve,
> I would like the javascript code that will do the client side filtering
> using Active-X. I am using msxml2 version 3 in replace mode and the
> browser is IE6. I have been trying to do client side sorting and
> filtering using this script taken from www.bayes.co.uk :
>
> function filter(userFirstName){
> try{
> var s = new
> ActiveXObject("MSXML2.FreeThreadedDOMDocument");
> var x = document.XMLDocument;
> if (x == null){
> x = navigator.XMLDocument;
> s.loadXML(navigator.XSLDocument.xml);
> }else{
> s.loadXML(document.XSLDocument.xml);
> }
> var tem = new ActiveXObject("MSXML2.XSLTemplate");
> tem.stylesheet = s;
> var proc = tem.createProcessor();
> proc.addParameter("userFirstName", userFirstName);
> proc.input = x;
> proc.transform();
> var str = proc.output;
>
> var newDoc = document.open("text/html");
> newDoc.write(str);
> navigator.XMLDocument = x;
> navigator.XSLDocument = s;
> newDoc.close();
> }catch(exception){
> }
> }
>
> I have incuded alerts all over the script and it craps on
> navigator.XMLDocument as undefined. Any help would be appreciated.
>
> Thanks
>
> Sam Awad
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Steve Gold
> Sent: Sunday, February 02, 2003 9:33 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: RE: [xsl] Filtering XML with XSL
>
>
> We do this running Microsoft Windows 2000 web server and XML 4.0 parser.
> Active Server Pages (ASP) does the transformation and it is very
> straightforward.  We also have a non-ASP version that does the XML to
> XSL transformation using JavaScript but this works on Internet Explorer
> only as it uses an Active-X, etc.  (We only really use that version when
> distributing the site on CD-ROM.)
>
> Our entire site is XML-based.
>
> As an example, one path visitors can take allows them to select a year,
> then see all the training courses for that year, grouped by month or
> topic.  Then they can click a month and see a calendar for that month or
> a schedule for that course, etc.  If your site will be running Windows
> 2000 web server, or if others are interested, I can provide the code.
> (Steve@xxxxxxxxxxxxx) It is all pretty cut and paste and works great.
>
> Hope this helps.
>
> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx] On Behalf Of James Hunt
> Sent: Saturday, February 01, 2003 6:55 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] Filtering XML with XSL
>
>
> I would like to develop a web site that involve allowing a user to
> choose a value from a combo box and then connect them to a site that
> filters a xml file from which item they have selected.
>
> For Example:
> If the user has a combo box with zip codes in it. When they select a zip
> codethey are led to another site that only shows the records with the
> specified zip code.
>
> Can someone point me to the right direction? If someone knows a site
> that has an example like this please let me know.
>
> Thanks,
> James
>
> XML Example:
> <Addresses>
>         <Address>
>             <StreetAddress>My Street</StreetAddresss>
>             <City>My City</City>
>             <State>OHIO</State>
>             <Zip>45111</Zip>
>         </Address>
>         <Address>
>             <StreetAddress>My Street 2</StreetAddresss>
>             <City>My City 2</City>
>             <State>OHIO</State>
>             <Zip>45141</Zip>
>         </Address>
>         <Address>
>             <StreetAddress>My Street 3</StreetAddresss>
>             <City>My City 3</City>
>             <State>OHIO</State>
>             <Zip>45211</Zip>
>         </Address>
> </Addresses>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread