[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

[xsl] XSL client side sorting using msXML2 version 3 in replace mode and IE6 - Only column heading are dislpayed - no record set - no errors


Subject: [xsl] XSL client side sorting using msXML2 version 3 in replace mode and IE6 - Only column heading are dislpayed - no record set - no errors
From: "Sam Awad" <sammy_awad@xxxxxxxxx>
Date: Wed, 22 Jan 2003 15:17:12 -0700

I have a functional "web part" (vbscript processed by the sharepoint digital
dashboard factory) that collects user data from W2K Active Directory and
pumps it, and an XSL file, into the DOM object to create an HTML display.

Here is the vbscript(just for reference - not problematic):
"""""""""""""""""""""""""""""""""""""""
Function GetContent(whatever)

Const adPersistXML = 1
Const adUseClient = 3
Const adOpenKeyset = 1
Const adLockOptimistic = 3
Const adReadAll = -1

Dim strConnection
Dim rs
Dim strSQL
Dim oStream
Dim strRst
Dim xmlBody
Dim displayWeb
Dim strBody
Dim oConn
Dim sUser
Dim sPassword

'Set up the connection to AD using a user that is a member of "domain users"
Set oConn = CreateObject("ADODB.Connection")
sUser = "domain\username"
sPassword = "password"

oConn.Provider = "ADsDSOObject"
oConn.open "ADProvider", sUser, sPassword

strConnection =
"'LDAP://your2kdomainname.com/OU=2ndlevelOUName,OU=1stlevelOUName,DC=your2kd
omainname,DC=com'"
strSQL = "select name, sn, givenName, telephonenumber, mobile,
physicalDeliveryOfficeName, mail, title from " & strConnection & " where
objectCategory='person' AND objectClass='user' order by sn asc "

'Get recordset
Set rs = CreateObject ("ADODB.RECORDSET")
rs.ActiveConnection = oConn
rs.CursorLocation = adUseClient
rs.Open strSQL, oConn, adOpenKeyset, adLockOptimistic

'Store Data in a stream object and convert to a string
Set oStream = CreateObject ("ADODB.STREAM")
rs.Save oStream, adPersistXML
strRst = oStream.ReadText(adReadAll)

'Load the strRst string which has XML data into xmlBody DOM object
Set xmlBody = CreateObject("MSXML2.domdocument")
xmlBody.async = False
xmlBody.LoadXML strRst

'Load the xsl file into xmlBody DOM Object
Set displayWeb = CreateObject("MSXML2.domdocument")
displayWeb.async = False
displayWeb.Load "EmployeeAD.xsl"
strBody = xmlBody.transformNode(displayWeb)

rs.close
oConn.close

getContent = strBody

'Cleanup
Set rs = Nothing
Set oConn = Nothing

End Function
"""""""""""""""""""""""""""""""""""""""""""""""

Now here is the simple XSL file:
""""""""""""""""""""""""""""""""""""""""""""""""
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
 <xsl:template match="/">
  <HTML>
   <BODY>
    <TABLE width="420">
     <tr bgcolor="Black">
      <td width="120"><font face="Verdana" size="1"
color="White"><b>Name</b></font></td>
      <td width="100"><font face="Verdana" size="1" color="White"><b>Office
Phone</b></font></td>
      <td width="100"><font face="Verdana" size="1" color="White"><b>Mobile
Phone</b></font></td>
     </tr>
  <xsl:for-each select="xml/rs:data/z:row">
  <TR bgcolor="#FAEBD7">
   <TD><font face="Verdana" size="1" color="black"><xsl:value-of
select="@name"/></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>
  </TR>
  </xsl:for-each>
    </TABLE>
   </BODY>
  </HTML>
 </xsl:template>
</xsl:stylesheet>
"""""""""""""""""""""""""""""""""""""""""""""""""""
All the above works just fine.
An xml file gets produced and a result is displayed in html.

Here is a short version of the 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>
"""""""""""""""""""""""""""""""""""""""""""""""""""

Now, I needed to be able to do client side sorting on the result by clicking
on the column heading, so I followed the example on
http://www.bayes.co.uk/xml/index.xml?/xml/tutorial/filtering/filter.xml but
have been unseccussfull and I am desperatley looking for help.

Here is my new xsl file:
Highlights of changes:
-displaying more columns (benign)
-namespace change
-added default parameter
-added sort javascript inside xsl file
-added onclick event handlers to column headings
-added if statement for sorting
-added template "ByChoice"


""""""""""""""""""""""""""""""""""""""""""""""""""""
<?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="'sn'" />

  <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 = 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>
    <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:apply-templates select="ByChoice">
        <xsl:sort select="@sn" order="ascending" />
       </xsl:apply-templates>
      </xsl:if>

      <xsl:if test="$column='givenName'">
       <xsl:apply-templates select="ByChoice">
        <xsl:sort select="@givenName" order="ascending" />
       </xsl:apply-templates>
      </xsl:if>

      <xsl:if test="$column='office'">
       <xsl:apply-templates select="ByChoice">
        <xsl:sort select="@physicalDeliveryOfficeName" order="ascending" />
       </xsl:apply-templates>
      </xsl:if>
     </TABLE>
   </BODY>
  </HTML>
 </xsl:template>

<xsl:template match="ByChoice">

 <xsl:for-each select="xml/rs:data/z:row">
  <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:value-of
select="@givenName"/></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:for-each>
</xsl:template>
</xsl:stylesheet>
"""""""""""""""""""""""""""""""""""""""""""""""""""""""
My problem: XML file gets created by the script still, however using the new
xsl file, only the cloumn headings get displayed and not the record set.
There are no errors. It seems as if everything runs fine (it takes 3 seconds
to output Column headings) but it cannot be displayed into the broswer.

I am running w2k server SP2 w/ sharepoint portal server sp1.
My server is using version 3 of MSxml2 in replace mode.
All my target and test clients are IE6 and above.

I am stuck. I really appreciate any help.
Thank you so much in advance.

Sam Awad



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



Keywords