Subject: Re: [xsl] Filtering XML with XSL From: "Charles White" <chuck@xxxxxxxxxxx> Date: Thu, 6 Feb 2003 21:30:10 -0800 |
Hi Sam: I'm not able to reproduce your errors. In fact, I'm not getting any. However, I have changed the Javascript a little. All I added was this to the sort() function: var newDoc = document.open("text/html"); newDoc.write(str); navigator.XMLDocument = x; navigator.XSLDocument = s; But that was because when I hit back nothing happened. I have included the Javascript I have in case I changed something else and I'm just not catching it. It helps to take out the exception handlers so you can debug. That way you won't just get silent failures, you'll get error messages showing where the problems are. Since I removed the exception handlers, you'll want to put them back in before you make this live. Anyway, this is the script I am using: <?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> <xsl:param name="column" select="'givenName'" /> <xsl:param name="userFirstName" select="''" /> <xsl:template match="/"> <HTML> <head> <script language="JScript"> function sort(column){ 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("column", column); proc.input = x; proc.transform(); var str = proc.output; var newDoc = document.open("text/html"); newDoc.write(str); navigator.XMLDocument = x; navigator.XSLDocument = s; } function filter(userFirstName){ 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; } </script> <script language="vbscript"> function printIt() window.print end function </script> <style type="text/css"> .head {cursor:hand;} </style> </head> <BODY id="output"> <xsl:choose> <xsl:when test="$userFirstName"> <xsl:apply-templates select="xml/rs:data/z:row[@givenName=$userFirstName]" mode="single" /> </xsl:when> <xsl:otherwise> <TABLE width="740"> <tr bgcolor="Black"> <td class="head" onclick="sort('sn')" width="40"><font face="Verdana" size="1" color="White"><b>Last</b></font></td> <td class="head" onclick="sort('givenName')" id="TEST" width="40"><font face="Verdana" size="1" color="White"><b>First</b></font></td> <td width="80"><font face="Verdana" size="1" color="White"><b>Title</b></font></td> <td class="head" onclick="sort('Office')" width="50"><font face="Verdana" size="1" color="White"><b>Office</b></font></td> <td width="100"><font face="Verdana" size="1" color="White"><b>Office Number</b></font></td> <td width="100"><font face="Verdana" size="1" color="White"><b>Mobile Number</b></font></td> <td width="100"><font face="Verdana" size="1" color="White"><b>Email</b></font></td> <td class="head" onclick="printIt()" width="20"><font face="Verdana" size="1" color="red"><b>PRINT</b></font></td> </tr> <xsl:if test="$column='sn'"> <xsl:for-each select="xml/rs:data/z:row"> <xsl:sort select="@sn" order="ascending" /> <xsl:call-template name="SortByChoice"> </xsl:call-template> </xsl:for-each> </xsl:if> <xsl:if test="$column='givenName'"> <xsl:for-each select="xml/rs:data/z:row"> <xsl:sort select="@givenName" order="ascending" /> <xsl:call-template name="SortByChoice"> </xsl:call-template> </xsl:for-each> </xsl:if> </TABLE> </xsl:otherwise> </xsl:choose> </BODY> </HTML> </xsl:template> <xsl:template name="SortByChoice"> <TR bgcolor="#FAEBD7"> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@sn"/></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:attribute name="onclick">filter('<xsl:value-of select="@givenName" />');</xsl:attribute><xsl:attribute name="style">cursor:hand;</xsl:attribute><xsl:attribute name="id"><xsl:value-of select="@givenName"/></xsl:attribute><u><xsl:value-of select="@givenName"/></u></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@title"/></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@physicalDeliveryOfficeName"/></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@telephonenumber"/></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@mobile"/></font></TD> <TD><font face="Verdana" size="1" color="black"><xsl:value-of select="@mail"/></font></TD> </TR> </xsl:template> <xsl:template match="xml/rs:data/z:row" mode="single"> <TABLE width="740"> <tr bgcolor="#ff8800"> <td align="center"><img><xsl:attribute name="src"><xsl:value-of select="@url"/></xsl:attribute></img></td> <td><font face="Verdana" size="1" color="black">Last Name:<xsl:value-of select="@sn" /><br />First Name:<xsl:value-of select="@givenName" /><br />Title:<xsl:value-of select="@title" /><br />Office Location:<xsl:value-of select="@physicalDeliveryOfficeName" /><br />Office Number:<xsl:value-of select="@telephonenumber" /><br />Mobile Number:<xsl:value-of select="@mobile" /><br />Email Address:<xsl:value-of select="@mail" /><br /></font></td> </tr> </TABLE> <div style="background-color:#FF8800;width:80%;"> <center> <a href="JavaScript:sort('{local-name(@sn)}')">Back</a> </center> </div> </xsl:template> </xsl:stylesheet> Note also that I included a PI directly in the test XML doc I am using. If you are acquiring your XML from Active Directory, it *should* still work, but life is funny, so who knows. Anyway, this is working fine on my machine, so if it doesn't for you, I'm punting. :-) Cheers, 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: Thursday, February 06, 2003 2:59 PM Subject: RE: [xsl] Filtering XML with XSL > Hi Chuck, > > I added the ID attribute and nothing has changed. > I think I misled you a little. My current XSL sheet accepts the parameters > (when I hardcode them in the begining) without a problem and I am able to > see the transformed data based on a certain parameter value. When I click on > my event handlers that call the JavaScript nothing happens and no errors are > displayed. > It is supposed to reload the XSLT and feed it the new parameter values upon > reload (like you mentioned about the use of XMLDocument and XSLDocument > properties). > So, I added alerts to the JavaScript and I see that the properties > document.XMLDocument and navigator.XMLDocument are empty, their value is > "undefined". Shouldn't I be seeing the XML sting in there? > > Sorry I am not very savvy at this but I am trying. > > Thanks again very much. > > > > -----Original Message----- > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Charles White > Sent: Thursday, February 06, 2003 1:26 AM > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > Subject: Re: [xsl] Filtering XML with XSL > > > Hi Sam: > > It makes sense that you are getting a bunch of errors telling you the object > doesn't exist, because the JScript engine is looking for objects named, for > example, in the case of the filter function, the actual given name. But you > have no id attribute assigned to the object, so the JScript processor can't > find the object. So, as just one example, do this: > > <xsl:attribute name="id"><xsl:value-of select="@givenName"/></xsl:attribute> > > I added this to your SortByTemplate template, and the JScript engine was > able to find the object and display the information okay. So, this is what > the beginning of that template now looks like (I added a cursor style > because it drives me crazy to see an onclick event with no hand cursor > associated with the event source): > > <xsl:template name="SortByChoice"> > <TR bgcolor="#FAEBD7"> > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > select="@sn"/></font></TD> > <TD><font face="Verdana" size="1" color="black"><xsl:attribute > name="onclick">filter('<xsl:value-of select="@givenName" > />');</xsl:attribute><xsl:attribute > name="style">cursor:hand;</xsl:attribute><xsl:attribute > name="id"><xsl:value-of > select="@givenName"/></xsl:attribute><u><xsl:value-of > select="@givenName"/></u></font></TD> > ... > > The only change is the additional xsl:attribute that creates an id > attribute. You could also have used attribute value templates, they're a bit > cleaner in my view, but this will work. You'll need to follow this procedure > whererever you have function calls. > > Cheers, > > 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 9:52 PM > Subject: RE: [xsl] Filtering XML with XSL > > > > Thanks for your help Chuck, > > > > Here is the xsl file that contains the JavaScript: > > > > <?xml version="1.0"?> > > <xsl:stylesheet version="1.0" > > xmlns:xsl="http://www.w3.org/1999/XSL/Transform" > > xmlns:s="uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882" > > xmlns:dt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882" > > xmlns:rs="urn:schemas-microsoft-com:rowset" xmlns:z="#RowsetSchema"> > > <xsl:param name="column" select="'givenName'" /> > > <xsl:param name="userFirstName" select="''" /> > > <xsl:template match="*|@*"> > > <xsl:copy> > > <xsl:apply-templates select="@* | * | comment() | > > processing-instruction() | text()" /> > > </xsl:copy> > > </xsl:template> > > <xsl:template match="/"> > > <HTML> > > <head> > > <script language="javascript"> > > function sort(column){ > > 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("column", column); > > proc.input = document.xmldocument; > > proc.transform(); > > var str = proc.output; > > > > var newDoc = document.open("text/html", "replace"); > > newDoc.write(str); > > navigator.XMLDocument = x; > > navigator.XSLDocument = s; > > newDoc.close(); > > }catch(exception){ > > } > > } > > > > 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){ > > } > > } > > </script> > > <script language="vbscript"> > > function printIt() > > window.print > > end function > > </script> > > </head> > > <BODY> > > <xsl:choose> > > <xsl:when test="$userFirstName"> > > <xsl:apply-templates > > select="xml/rs:data/z:row[@givenName=$userFirstName]" mode="single" /> > > </xsl:when> > > <xsl:otherwise> > > <TABLE width="740"> > > <tr bgcolor="Black"> > > <td class="head" onclick="sort('sn')" width="40"><font > face="Verdana" > > size="1" color="White"><b>Last</b></font></td> > > <td class="head" onclick="sort('givenName')" width="40"><font > > face="Verdana" size="1" color="White"><b>First</b></font></td> > > <td width="80"><font face="Verdana" size="1" > > color="White"><b>Title</b></font></td> > > <td class="head" onclick="sort('Office')" width="50"><font > > face="Verdana" size="1" color="White"><b>Office</b></font></td> > > <td width="100"><font face="Verdana" size="1" > color="White"><b>Office > > Number</b></font></td> > > <td width="100"><font face="Verdana" size="1" > color="White"><b>Mobile > > Number</b></font></td> > > <td width="100"><font face="Verdana" size="1" > > color="White"><b>Email</b></font></td> > > <td class="head" onclick="printIt()" width="20"><font face="Verdana" > > size="1" color="red"><b>PRINT</b></font></td> > > </tr> > > <xsl:if test="$column='sn'"> > > <xsl:for-each select="xml/rs:data/z:row"> > > <xsl:sort select="@sn" order="ascending" /> > > <xsl:call-template name="SortByChoice"> > > </xsl:call-template> > > </xsl:for-each> > > </xsl:if> > > <xsl:if test="$column='givenName'"> > > <xsl:for-each select="xml/rs:data/z:row"> > > <xsl:sort select="@givenName" order="ascending" /> > > <xsl:call-template name="SortByChoice"> > > </xsl:call-template> > > </xsl:for-each> > > </xsl:if> > > </TABLE> > > </xsl:otherwise> > > </xsl:choose> > > </BODY> > > </HTML> > > </xsl:template> > > <xsl:template name="SortByChoice"> > > <TR bgcolor="#FAEBD7"> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@sn"/></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:attribute > > name="onclick">filter('<xsl:value-of select="@givenName" > > />');</xsl:attribute><u><xsl:value-of > select="@givenName"/></u></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@title"/></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@physicalDeliveryOfficeName"/></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@telephonenumber"/></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@mobile"/></font></TD> > > <TD><font face="Verdana" size="1" color="black"><xsl:value-of > > select="@mail"/></font></TD> > > </TR> > > </xsl:template> > > > > <xsl:template match="xml/rs:data/z:row" mode="single"> > > <TABLE width="740"> > > <tr bgcolor="#ff8800"> > > <td align="center"><img><xsl:attribute name="src"><xsl:value-of > > select="@url"/></xsl:attribute></img></td> > > <td><font face="Verdana" size="1" color="black">Last Name:<xsl:value-of > > select="@sn" /><br />First Name:<xsl:value-of select="@givenName" /><br > > />Title:<xsl:value-of select="@title" /><br />Office > Location:<xsl:value-of > > select="@physicalDeliveryOfficeName" /><br />Office Number:<xsl:value-of > > select="@telephonenumber" /><br />Mobile Number:<xsl:value-of > > select="@mobile" /><br />Email Address:<xsl:value-of select="@mail" /><br > > /></font></td> > > </tr> > > </TABLE> > > <div style="background-color:#FF8800;width:80%;"> > > <center> > > <a href="JavaScript:sort('sn')">Back</a> > > </center> > > </div> > > </xsl:template> > > </xsl:stylesheet> > > =================================================== > > > > Also, here is a short version of the generated xml file: > > > > ==================================================== > > <xml xmlns:s='uuid:BDC6E3F0-6DA3-11d1-A2A3-00AA00C14882' > > xmlns:dt='uuid:C2F41010-65B3-11d1-A29F-00AA00C14882' > > xmlns:rs='urn:schemas-microsoft-com:rowset' > > xmlns:z='#RowsetSchema'> > > <s:Schema id='RowsetSchema'> > > <s:ElementType name='row' content='eltOnly' rs:updatable='true'> > > <s:AttributeType name='title' rs:number='1' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='mail' rs:number='2' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='physicalDeliveryOfficeName' rs:number='3' > > rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='mobile' rs:number='4' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='telephonenumber' rs:number='5' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='givenName' rs:number='6' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='sn' rs:number='7' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:AttributeType name='name' rs:number='8' rs:nullable='true'> > > <s:datatype dt:type='string' dt:maxLength='256' rs:maybenull='false'/> > > </s:AttributeType> > > <s:extends type='rs:rowbase'/> > > </s:ElementType> > > </s:Schema> > > <rs:data> > > <z:row mail='someone@xxxxxxxxxxxxx' physicalDeliveryOfficeName='someplace' > > mobile='111-570-6533' telephonenumber='111-239-1053' > > givenName='Anthony' sn='Peters' name='Anthony Peters'/> > > <z:row title='Engineering Project Manager' > > mail='sometwo@xxxxxxxxxxxxx' physicalDeliveryOfficeName='other place' > > mobile='111-371-6810' > > telephonenumber='111-531-7249' givenName='John' sn='Allen' name='John > > Allen'/> > > </rs:data> > > </xml> > > """"""""""""""""""""""""""""""""""""""""""""""""""" > > > > -----Original Message----- > > From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of Charles White > > Sent: Wednesday, February 05, 2003 6:13 PM > > To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx > > Subject: Re: [xsl] Filtering XML with XSL > > > > > > 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. > > > > > > > > > > > > -- 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] Filtering XML with XSL, Steve Gold | Thread | RE: [xsl] Filtering XML with XSL, Sam Awad |
[xsl] pcl output, Bill McDaniel | Date | Re: [xsl] pcl output, Charles White |
Month |