Solved

Click Sorting in xsl

Posted on 2001-07-15
32
334 Views
Last Modified: 2006-11-17
Hello Experts,
   I am displaying the data with xml using xsl by transforming. I am not saving the xml at all. The data is in the tabular form with cols like Name Id, Address and all and hundreds of rows. On the click of Header, I want to sort the data, with that header. Suppose I click on name, then the data must sort by name just by using script on that page. So if any one can help me??
Regards
Nitin
0
Comment
Question by:nitinafre
  • 14
  • 7
  • 5
  • +2
32 Comments
 
LVL 11

Expert Comment

by:sachiek
ID: 6284832
Hi there
   Tell ur E-maill address,. I will e-mail you the code.

 Cheers!!
Sachi
0
 
LVL 2

Expert Comment

by:MicOfLZ
ID: 6285200
have a look at this:

http://msdn.microsoft.com/xml/samples/stock-sorter/stock-sorter.xml

Think that helps
MicOfLZ
0
 
LVL 2

Expert Comment

by:MicOfLZ
ID: 6285203
ohoh - old link !
one moment.
0
 
LVL 2

Expert Comment

by:MicOfLZ
ID: 6285210
0
 

Author Comment

by:nitinafre
ID: 6288092
For MicOfLZ,
   I have to study the code and try.
For Sachi,
   Here is my mail address. nitinafre@yahoo.com. But better if you put the code here only.
Thanx for the responses.
Nitin

0
 
LVL 11

Expert Comment

by:sachiek
ID: 6288378
Hi there
  Ok I will post it as part by part msgs.

Note: this is all happen in client side only.


First one is

default.asp

----------------------------

<%@Language="VBScript"%>
<html>
<head>

<style type="text/css">
body{ font:'8pt Verdana, Arial'; }
table{ font:'lighter 8pt Verdana, Arial'; border-right:'1px solid #336699'; }
td{ border-left:'1px solid #336699'; border-bottom:'1px solid #336699'; vertical-align:top;}
input{ font:'8pt Verdana, Arial'; }
a{ color:darkblue; }
a:hover{ color:red; }
</style>

<xml id="XMLDOM" src="GetXML.asp?<%=Request.QueryString%>"></xml>
<xml id="XSLDOM" src="Sample.xsl"></xml>

<script language="JavaScript">
/*
 * This method changes the values of the sorting and ordering
 * variables inserted into the first script block of the XSL.
 */
function ChangeOrder(Order,By){
  //Set the query right.
  if( Order == null ) Order="+ ";
  if( By == null ) By="ID";
  XSLDOM.XMLDocument.selectSingleNode("/xsl:stylesheet/xsl:template/table/xsl:for-each/@order-by").nodeValue = (Order + By);
  //Set the scripting variables right.
  var order = 'var order="' +Order+ '";';
  var by    = 'var by="' +By+ '";';
  var oNode = XSLDOM.XMLDocument.selectSingleNode("/xsl:stylesheet/xsl:script[@id='OrderVars']");
  oNode.text = order+ '\n' +by+ '\n';
  //Reset to beginning of page since order has changed.
  ChangePaging(0,txtPageSize.value);
}

/*
 * This method changes which of the displayed items is shown (page size).
 */
function ChangePaging(PageLB,PageSize){
  //This section was rem'd since indexing was
  //  taking precedence over the order by.
  //  (Thus causing things to only sort within
  //   the given page size and not outside.)
  //Set the query right.
  //var Query = "Item[index() $ge$ " +PageLB+ " $and$ index() $lt$ " +(PageLB+PageSize)+ "]";
  //XSLDOM.selectSingleNode("/xsl:stylesheet/xsl:template/table/xsl:for-each/xsl:if/@match").nodeValue = Query;
  //Set the scripting variables right.
  var pageLB   = 'var PageLB=' +PageLB+ ';';
  var pageSize = 'var PageSize=' +PageSize+ ';';
  var oNode = XSLDOM.XMLDocument.selectSingleNode("/xsl:stylesheet/xsl:script[@id='PagingVars']");
  oNode.text = pageLB+ '\n' +pageSize+ '\n';
  //Transform.
  ShowTransform();
}

/*
 * This method processes the XML through the XSL and outputs the result
 * into the div container.
 */
function ShowTransform(){
  TransformContainer.innerHTML = XMLDOM.XMLDocument.transformNode(XSLDOM.XMLDocument);
}
</script>

<script language="JavaScript" for="window" event="onload">
ShowTransform();
</script>

</head>

<body>
<div>
     Page Size:
     <input id="txtPageSize" type="text" value="5" size="1" onkeypress="if(window.event.keyCode==13)ChangePaging(0,txtPageSize.value);"></input>
     <input type="button" value="Submit" onclick="ChangePaging(0,txtPageSize.value);"></input>
     <input type="button" value="Reset" onclick="window.location='default.asp';"></input>
</div>
<div id="TransformContainer" name="TransformContainer">&nbsp;</div>
</body>

</html>
0
 
LVL 11

Expert Comment

by:sachiek
ID: 6288379
Secound one..

getxml.asp
------------------------

<%@Language=VBScript %>
<%
'===============================================================
'File:            GetXML.asp
'Params:      None
'Output:      XML
'Author:      Adam Griffin
'Date:            05/18/2000
'===============================================================

Response.Buffer = True
Response.ContentType = "text/xml"
Response.Write "<?xml version=""1.0""?>"

'Normally, you would could get any parameters
'from the querystring and create any COM
'objects here that would return XML.  This
'is just a sample so, we will return static
'XML.
%>
<Recordset>
      <Row>
            <ID>
                  <![CDATA[153140]]>
            </ID>
            <FName>
                  <![CDATA[Vinh]]>
            </FName>
            <MName>
                  <![CDATA[Xuan]]>
            </MName>
            <LName>
                  <![CDATA[Phung]]>
            </LName>
            <Alias>
                  <![CDATA[X Man]]>
            </Alias>
            <Profession>
                  <![CDATA[System Telecom Engineering Manager]]>
            </Profession>
            <DOB>
                  <![CDATA[4/20/1965]]>
            </DOB>
            <Quote>
                  <![CDATA[I could tell you but, I'd have to kill you.]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[112075]]>
            </ID>
            <FName>
                  <![CDATA[Anna]]>
            </FName>
            <MName>
                  <![CDATA[M.]]>
            </MName>
            <LName>
                  <![CDATA[Griffin]]>
            </LName>
            <Alias>
                  <![CDATA[S.P.K.]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[11/20/1975]]>
            </DOB>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153141]]>
            </ID>
            <FName>
                  <![CDATA[Adrienne]]>
            </FName>
            <MName>
                  <![CDATA[L.]]>
            </MName>
            <LName>
                  <![CDATA[Kirtland]]>
            </LName>
            <Alias>
                  <![CDATA[Red]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[8/24/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[Yea yea yea]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153142]]>
            </ID>
            <FName>
                  <![CDATA[Josh]]>
            </FName>
            <MName>
                  <![CDATA[D.]]>
            </MName>
            <LName>
                  <![CDATA[Howell]]>
            </LName>
            <Alias>
                  <![CDATA[Shakes]]>
            </Alias>
            <Profession>
                  <![CDATA[E-Net Manager]]>
            </Profession>
            <DOB>
                  <![CDATA[2/26/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[Get so hype.]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153143]]>
            </ID>
            <FName>
                  <![CDATA[T.]]>
            </FName>
            <MName>
                  <![CDATA[Steve]]>
            </MName>
            <LName>
                  <![CDATA[Creason]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Narcotics Officer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/4/1962]]>
            </DOB>
            <Quote>
                  <![CDATA[You're go'n down, punk.]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153144]]>
            </ID>
            <FName>
                  <![CDATA[Dan]]>
            </FName>
            <MName>
                  <![CDATA[Julias]]>
            </MName>
            <LName>
                  <![CDATA[Tancredi]]>
            </LName>
            <Alias>
                  <![CDATA[D.T.M.]]>
            </Alias>
            <Profession>
                  <![CDATA[Investment Banker]]>
            </Profession>
            <DOB>
                  <![CDATA[12/20/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[Yeaaaa....]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153145]]>
            </ID>
            <FName>
                  <![CDATA[Erin]]>
            </FName>
            <MName>
                  <![CDATA[E.]]>
            </MName>
            <LName>
                  <![CDATA[Midkiff]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Student]]>
            </Profession>
            <DOB>
                  <![CDATA[9/19/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153146]]>
            </ID>
            <FName>
                  <![CDATA[Karen]]>
            </FName>
            <MName>
                  <![CDATA[M.]]>
            </MName>
            <LName>
                  <![CDATA[Bramlett]]>
            </LName>
            <Alias>
                  <![CDATA[Mariah]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[4/5/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[What a girl wants...]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153147]]>
            </ID>
            <FName>
                  <![CDATA[Jason]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Tsai]]>
            </LName>
            <Alias>
                  <![CDATA[Kryme Dog]]>
            </Alias>
            <Profession>
                  <![CDATA[Mechanical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1975]]>
            </DOB>
            <Quote>
                  <![CDATA[Micks sucks!]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153148]]>
            </ID>
            <FName>
                  <![CDATA[Larry]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Rasoulian]]>
            </LName>
            <Alias>
                  <![CDATA[Ice]]>
            </Alias>
            <Profession>
                  <![CDATA[Chemical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[6/20/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[I'm roll'n down Peachtree]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153149]]>
            </ID>
            <FName>
                  <![CDATA[A.]]>
            </FName>
            <MName>
                  <![CDATA[Freeman]]>
            </MName>
            <LName>
                  <![CDATA[York]]>
            </LName>
            <Alias>
                  <![CDATA[Freedawg]]>
            </Alias>
            <Profession>
                  <![CDATA[Software Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1975]]>
            </DOB>
            <Quote>
                  <![CDATA[C-4]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153150]]>
            </ID>
            <FName>
                  <![CDATA[Linda]]>
            </FName>
            <MName>
                  <![CDATA[P.]]>
            </MName>
            <LName>
                  <![CDATA[Conforti]]>
            </LName>
            <Alias>
                  <![CDATA[Lush]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[1/26/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[More wine please]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153151]]>
            </ID>
            <FName>
                  <![CDATA[Dan]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Spickard]]>
            </LName>
            <Alias>
                  <![CDATA[Lush]]>
            </Alias>
            <Profession>
                  <![CDATA[Sports Journalist]]>
            </Profession>
            <DOB>
                  <![CDATA[4/10/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[More beer please]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153152]]>
            </ID>
            <FName>
                  <![CDATA[Paul]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Houston]]>
            </LName>
            <Alias>
                  <![CDATA[Too tall Paul]]>
            </Alias>
            <Profession>
                  <![CDATA[Mechanical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153153]]>
            </ID>
            <FName>
                  <![CDATA[Candy]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Houston]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Industrial Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153154]]>
            </ID>
            <FName>
                  <![CDATA[Emily]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Neer]]>
            </LName>
            <Alias>
                  <![CDATA[M]]>
            </Alias>
            <Profession>
                  <![CDATA[Industrial Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/7/1977]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[7]]>
            </ID>
            <FName>
                  <![CDATA[Adam]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Griffin]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Web Developer]]>
            </Profession>
            <DOB>
                  <![CDATA[11/2/4538]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
</Recordset>
0
 
LVL 11

Expert Comment

by:sachiek
ID: 6288382
Third one:


Sample.xml
---------------------------

<?xml-stylesheet type="text/xsl" href="Sample.xsl"?>
<Recordset>
      <Row>
            <ID>
                  <![CDATA[153140]]>
            </ID>
            <FName>
                  <![CDATA[Vinh]]>
            </FName>
            <MName>
                  <![CDATA[Xuan]]>
            </MName>
            <LName>
                  <![CDATA[Phung]]>
            </LName>
            <Alias>
                  <![CDATA[X Man]]>
            </Alias>
            <Profession>
                  <![CDATA[Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[4/20/1965]]>
            </DOB>
      </Row>
      <Row>
            <ID>
                  <![CDATA[112075]]>
            </ID>
            <FName>
                  <![CDATA[Anna]]>
            </FName>
            <MName>
                  <![CDATA[M.]]>
            </MName>
            <LName>
                  <![CDATA[Griffin]]>
            </LName>
            <Alias>
                  <![CDATA[S.P.K.]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[11/20/1975]]>
            </DOB>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153141]]>
            </ID>
            <FName>
                  <![CDATA[Adrienne]]>
            </FName>
            <MName>
                  <![CDATA[L.]]>
            </MName>
            <LName>
                  <![CDATA[Kirtland]]>
            </LName>
            <Alias>
                  <![CDATA[Red]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[8/24/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[Yea yea yea]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153142]]>
            </ID>
            <FName>
                  <![CDATA[Josh]]>
            </FName>
            <MName>
                  <![CDATA[D.]]>
            </MName>
            <LName>
                  <![CDATA[Howell]]>
            </LName>
            <Alias>
                  <![CDATA[Shakes]]>
            </Alias>
            <Profession>
                  <![CDATA[E-Net Manager]]>
            </Profession>
            <DOB>
                  <![CDATA[2/26/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[Get so hype.]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153143]]>
            </ID>
            <FName>
                  <![CDATA[T.]]>
            </FName>
            <MName>
                  <![CDATA[Steve]]>
            </MName>
            <LName>
                  <![CDATA[Creason]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Narcotics Officer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/4/1962]]>
            </DOB>
            <Quote>
                  <![CDATA[You're go'n down, punk.]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153144]]>
            </ID>
            <FName>
                  <![CDATA[Dan]]>
            </FName>
            <MName>
                  <![CDATA[Julias]]>
            </MName>
            <LName>
                  <![CDATA[Tancredi]]>
            </LName>
            <Alias>
                  <![CDATA[D.T.M.]]>
            </Alias>
            <Profession>
                  <![CDATA[Investment Banker]]>
            </Profession>
            <DOB>
                  <![CDATA[12/20/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[Yeaaaa....]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153145]]>
            </ID>
            <FName>
                  <![CDATA[Erin]]>
            </FName>
            <MName>
                  <![CDATA[E.]]>
            </MName>
            <LName>
                  <![CDATA[Midkiff]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Student]]>
            </Profession>
            <DOB>
                  <![CDATA[9/19/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153146]]>
            </ID>
            <FName>
                  <![CDATA[Karen]]>
            </FName>
            <MName>
                  <![CDATA[M.]]>
            </MName>
            <LName>
                  <![CDATA[Bramlett]]>
            </LName>
            <Alias>
                  <![CDATA[Mariah]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[4/5/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[What a girl wants...]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153147]]>
            </ID>
            <FName>
                  <![CDATA[Jason]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Tsai]]>
            </LName>
            <Alias>
                  <![CDATA[Kryme Dog]]>
            </Alias>
            <Profession>
                  <![CDATA[Mechanical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1975]]>
            </DOB>
            <Quote>
                  <![CDATA[Micks sucks!]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153148]]>
            </ID>
            <FName>
                  <![CDATA[Larry]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Rasoulian]]>
            </LName>
            <Alias>
                  <![CDATA[Ice]]>
            </Alias>
            <Profession>
                  <![CDATA[Chemical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[6/20/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[I'm roll'n down Peachtree]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153149]]>
            </ID>
            <FName>
                  <![CDATA[A.]]>
            </FName>
            <MName>
                  <![CDATA[Freeman]]>
            </MName>
            <LName>
                  <![CDATA[York]]>
            </LName>
            <Alias>
                  <![CDATA[Freedawg]]>
            </Alias>
            <Profession>
                  <![CDATA[Software Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1975]]>
            </DOB>
            <Quote>
                  <![CDATA[C-4]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153150]]>
            </ID>
            <FName>
                  <![CDATA[Linda]]>
            </FName>
            <MName>
                  <![CDATA[P.]]>
            </MName>
            <LName>
                  <![CDATA[Conforti]]>
            </LName>
            <Alias>
                  <![CDATA[Lush]]>
            </Alias>
            <Profession>
                  <![CDATA[Pharmacist]]>
            </Profession>
            <DOB>
                  <![CDATA[1/26/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[More wine please]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153151]]>
            </ID>
            <FName>
                  <![CDATA[Dan]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Spickard]]>
            </LName>
            <Alias>
                  <![CDATA[Lush]]>
            </Alias>
            <Profession>
                  <![CDATA[Sports Journalist]]>
            </Profession>
            <DOB>
                  <![CDATA[4/10/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[More beer please]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153152]]>
            </ID>
            <FName>
                  <![CDATA[Paul]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Houston]]>
            </LName>
            <Alias>
                  <![CDATA[Too tall Paul]]>
            </Alias>
            <Profession>
                  <![CDATA[Mechanical Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1974]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153153]]>
            </ID>
            <FName>
                  <![CDATA[Candy]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Houston]]>
            </LName>
            <Alias>
                  <![CDATA[]]>
            </Alias>
            <Profession>
                  <![CDATA[Industrial Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/1/1976]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
      <Row>
            <ID>
                  <![CDATA[153154]]>
            </ID>
            <FName>
                  <![CDATA[Emily]]>
            </FName>
            <MName>
                  <![CDATA[]]>
            </MName>
            <LName>
                  <![CDATA[Neer]]>
            </LName>
            <Alias>
                  <![CDATA[M]]>
            </Alias>
            <Profession>
                  <![CDATA[Industrial Engineer]]>
            </Profession>
            <DOB>
                  <![CDATA[1/7/1977]]>
            </DOB>
            <Quote>
                  <![CDATA[]]>
            </Quote>
      </Row>
</Recordset>
0
 
LVL 11

Expert Comment

by:sachiek
ID: 6288385
Fourth one


sample.xsl

----------------------


<?xml version="1.0" encoding="UTF-8"?>
<!--
  Filename:      Sample.xsl
  Author:      Adam Griffin
  Date:            05/18/2000
  Purpose:      To layout a list.
  Input:      XML
  Output:      HTML
-->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl" language="JavaScript">

<xsl:script language="JavaScript" id="OrderVars">
<![CDATA[
//default values(normally set by outside java functions).
var order ="";
var by="";
]]>
</xsl:script>

<xsl:script language="JavaScript" id="PagingVars">
<![CDATA[
//default values(normally set by outside java functions).
var PageLB = 0;   //current page lower bound.
var PageSize = 5; //current page size.
]]>
</xsl:script>

<xsl:script language="JavaScript">
<![CDATA[
/*
 * This function sets the directional
 * indicator for the Heading sort link.
 * It also returns the proper direction
 * for the sort function.
 */
var Link;
function GetSortLink(By){
  if( By == by ){
    //Change direction.
      if( order == "+ " ){
        Link = "??";
        return( '- ' );
      }else{
        Link = "??";
        return( '+ ' );
      }
  }else{
    Link = " ";
    return( '+ ' );
  }
}

/*
 * This function sets the paging boundaries
 * for all paging purposes.
 */
var PrevLB; //previous page's lower bound.
var NextLB; //next page's lower bound.
var PrevLink = "<--Prev"; //&#9668;-- Use this when Unicode supported.
var NextLink = "Next-->"; //--&#9658; Use this when Unicode supported.
var Max;
var PageUB;
function SetPageBounds(LastNode){
  if(LastNode==null){
    Max = 0;
  }else{
    Max = childNumber(LastNode);
  }
  PrevLB = PageLB - PageSize; //(6-10) becomes (1-5)
  NextLB = PageLB + PageSize; //(1-5)  becomes (6-10)
  if(PrevLB < 0) PrevLink = "";
  if(NextLB >= Max){
    NextLink = "";
    PageUB = Max;
  }else{
    PageUB = NextLB;
  }
}
/*
 * This function decides if the output is
 * within the displayable range of the
 * current page.
 */
var Counter = 0;
function ShowOutput(){
  if((Counter >= PageLB) && (Counter < (PageLB+PageSize))){
    Counter++;
    return(true);
  }else{
    Counter++;
    return(false);
  }
}

/*
 * This function is responsible for toggling
 * the color of alternating rows.
 */
var Toggle = true;
var Color = "";
function SetColor(){
  Toggle = !Toggle;
  if(Toggle) Color = "#B0C4DE"; //LightSteelBlue
  else Color = "#FFFFFF";
}

/*
 * This function will return a properly formated date.
 */
var MonthArray = new Array("Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec");
function GetFormatedDate(date){
  var d = date.match(/\d+/g); //Gets all numbers from the date string.
  //d is now a date array with the following position values.
  //0:Month|1:Date|2:Year|3:Hour|4:Min
  if( d[1]<10 ) d[1] = "0"+d[1];
  return( MonthArray[d[0]-1]+" "+d[1]+", "+d[2] );  //MMM.DD.YYYY format.
}
]]>
</xsl:script>

<xsl:template match="/">
      <table cellspacing="0" cellpadding="2" width="100%" style="border-right:0px;">
      <tr>
            <xsl:eval>SetPageBounds(this.selectSingleNode("Recordset/Row[end()]"));</xsl:eval>
            <td align="left"   nowrap="" style="border-left:0px;"> <a><xsl:attribute name="href">JavaScript:ChangePaging(<xsl:eval>PrevLB;</xsl:eval>,<xsl:eval>PageSize;</xsl:eval>);</xsl:attribute><xsl:eval>PrevLink;</xsl:eval></a><br/></td>
            <td align="center" nowrap="" style="border-left:0px;"> <xsl:eval>"Currently viewing " +(PageLB+1)+ " through " +(PageUB)+ " of " +Max+ " total items.";</xsl:eval></td>
            <td align="right"  nowrap="" style="border-left:0px;"> <a><xsl:attribute name="href">JavaScript:ChangePaging(<xsl:eval>NextLB;</xsl:eval>,<xsl:eval>PageSize;</xsl:eval>);</xsl:attribute><xsl:eval>NextLink;</xsl:eval></a><br/></td>
      </tr>
      </table>
      <table cellspacing="0" cellpadding="2" width="100%">
      <tr bgcolor="lightgrey">
            <!--1--><td width="60"   nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("number(ID)");</xsl:eval>','number(ID)');</xsl:attribute><xsl:eval>Link;</xsl:eval> ID</a>        </td>
            <!--2--><td width="100"  nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("FName");     </xsl:eval>','FName');       </xsl:attribute><xsl:eval>Link;</xsl:eval> F.Name</a>    </td>
            <!--4--><td width="100"  nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("LName");     </xsl:eval>','LName');     </xsl:attribute><xsl:eval>Link;</xsl:eval> L.Name</a>    </td>
            <!--5--><td width="100"  nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("Profession");</xsl:eval>','Profession');</xsl:attribute><xsl:eval>Link;</xsl:eval> Profession</a></td>
            <!--6--><td width="100"  nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("date(DOB)"); </xsl:eval>','date(DOB)'); </xsl:attribute><xsl:eval>Link;</xsl:eval> D.O.B.</a>    </td>
            <!--7--><td width="100%" nowrap=""> <a><xsl:attribute name="href">JavaScript:ChangeOrder('<xsl:eval>GetSortLink("Quote");     </xsl:eval>','Quote');     </xsl:attribute><xsl:eval>Link;</xsl:eval> Quote</a>     </td>
      </tr>
      <xsl:for-each select="Recordset/Row" order-by="nada">  <!-- [index() $ge$ 0 $and$ index() $lt$ 5] indexing takes precedence before sorting (not wanted). -->
            <xsl:if expr="ShowOutput();">
                  <xsl:eval>SetColor();</xsl:eval>
                  <tr><xsl:attribute name="bgcolor"><xsl:eval>Color;</xsl:eval></xsl:attribute>
                        <!--1--><td><xsl:value-of select="ID"/>     <br/></td>
                        <!--2--><td><xsl:value-of select="FName"/>  <br/></td>
                        <!--4--><td><xsl:value-of select="LName"/>  <br/></td>
                        <!--5--><td><xsl:value-of select="Profession"/>  <br/></td>
                        <!--6--><td><xsl:if test="DOB"><xsl:eval>GetFormatedDate(this.selectSingleNode("DOB").text);</xsl:eval></xsl:if>  <br/></td>
                        <!--7--><td><xsl:value-of select="Quote"/>  <br/></td>
                  </tr>
            </xsl:if>
      </xsl:for-each>
      </table>
</xsl:template>

</xsl:stylesheet>


0
 
LVL 11

Expert Comment

by:sachiek
ID: 6288387
Ok..Put it in a virtual directory and access all. You will see cool result.

Then explore the result u wanted.

Cheers!!
Sachi
0
 

Author Comment

by:nitinafre
ID: 6291915
Sachi,
   Thanks for the whole code. I need to try it and mould it as per my requirement. so need some time to reply.
Thanx again.
Nitin
0
 
LVL 2

Expert Comment

by:udnimbalkar
ID: 6309222
Hello Friend ,
   good example for you.This you will like.
check it out.
  Regards,
   Umesh Nimbalkar
   udnimbalkar@hotmail.com

--------------------------------------
fleet.xml

<?xml:stylesheet type="text/xsl" href="customer.xsl"?>
<fleet xmlns="x-schema:fleet-schema.xml">
      <description>Fleet Details</description>
      <customer>
            <custcode>c0001</custcode>
            <make>Tata</make>
            <model>LPT1613</model>
            <year>1993</year>
            <quantity>10</quantity>
      </customer>
      <customer>
            <custcode>c0002</custcode>
            <make>Tata</make>
            <model>LPT407</model>
            <year>1997</year>
            <quantity>4</quantity>
      </customer>
      <customer>
            <custcode>c0001</custcode>
            <make>Ashok</make>
            <model>11.10</model>
            <year>1998</year>
            <quantity>8</quantity>
      </customer>
      <customer>
            <custcode>c0003</custcode>
            <make>Tata</make>
            <model>1613</model>
            <year>1997</year>
            <quantity>12</quantity>
      </customer>
      <customer>
            <custcode>c0004</custcode>
            <make>Ashok</make>
            <model>11.10</model>
            <year>2000</year>
            <quantity>1</quantity>
      </customer>
      <customer>
            <custcode>c0005</custcode>
            <make>Tata</make>
            <model>LPT1613</model>
            <year>1997</year>
            <quantity>15</quantity>
      </customer>
      <customer>
            <custcode>c0005</custcode>
            <make>Tata</make>
            <model>LPT1018</model>
            <year>1999</year>
            <quantity>1</quantity>
      </customer>
</fleet>
------------------------------------------
customers.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
            <HTML>
                  <HEAD>
                        <STYLE>
                            BODY {margin:0; background-color="ivory"}
                            .bg {font:8pt Verdana; background-color:red; color:#000000; text="#000000"}
                            H1 {font:bold 14pt Verdana; width:100%; margin-top:1em; color:"#8b0000"}
                            H4 {font:bold 10pt Verdana; width:100%; margin-left:1em; color:"#8b0000"}
                            .row {bgColor="red" borderColorDark=#fcfcfc borderColorLight=#cccccc}
                            .header {borderColorDark:#f0f0f0 borderColorLight:#999999}
                            .new {background-color:#EEFFFD;}
                            .cheap {background-color:#FFDDDD;}
                    </STYLE>
                  </HEAD>
                  <!-- Sort Function -->
                  <SCRIPT>
                        <xsl:comment>
                              <![CDATA[
                            function sort(field)
                            {
                              sortField.value = field;
                              listing.innerHTML = source.documentElement.transformNode(stylesheet);
                            }



                        ]]>
                        </xsl:comment>
                  </SCRIPT>
                  <!-- Window OnLoad Function -->
                  <SCRIPT for="window" event="onload">
                        <xsl:comment>
                              <![CDATA[
                          stylesheet = document.XSLDocument;
                          source = document.XMLDocument;
                          sortField = document.XSLDocument.selectSingleNode("//@order-by");
                        ]]>
                        </xsl:comment>
                  </SCRIPT>
                  <!-- Start of HTML Body -->
                  <BODY>
                        <H1 align="center">
                              <xsl:value-of select="fleet/description"/>
                        </H1>
                        <p/>
                        <DIV id="listing">
                              <xsl:apply-templates select="fleet"/>
                        </DIV>
                        Total customers: <B>
                              <xsl:eval>custcount(this)</xsl:eval>
                        </B>
                        <BR/>
                        Average Vehicles: <B>
                              <xsl:eval>averageQty(this)</xsl:eval>
                        </B>
                        <BR/>
                        Max Vehicles: <B>
                              <xsl:eval>max1(this)</xsl:eval>
                        </B>
                        <BR/>
                        Minimum Vehicles: <B>
                              <xsl:eval>min1(this)</xsl:eval>
                        </B>
                        <BR/>
                        <BR/>
                  </BODY>
                  <!-- End of HTML Body -->
            </HTML>
      </xsl:template>
      <!-- Start of Templates -->
      <xsl:template match="fleet">
            <TABLE border="1" borderColor="white" cellPadding="2" cellSpacing="1" valign="TOP" align="center">
                  <TR bgColor="#cccccc" borderColorDark="#fcfcfc" borderColorLight="#999999">
                        <TD width="100">
                              <DIV onClick="sort('custcode')">Customer Code</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('make')">Make</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('model')">Model</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('year')">Year of Mfg.</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('quantity')">Quantity</DIV>
                        </TD>
                  </TR>
                  <xsl:for-each select="customer" order-by="custcode">
                        <TR bgColor="#f0f0f0" borderColorDark="#fcfcfc" borderColorLight="#cccccc">
                              <!-- highlight Tata models -->
                              <xsl:for-each select="make">
                                    <xsl:if expr="this.nodeTypedValue == 'Tata'">
                                          <xsl:attribute name="class">new</xsl:attribute>
                                    </xsl:if>
                              </xsl:for-each>
                              <TD>
                                    <DIV>
                                          <xsl:value-of select="custcode"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row">
                                          <xsl:value-of select="make"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row">
                                          <xsl:value-of select="model"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row" STYLE="text-align:center">
                                          <xsl:apply-templates select="year"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV>
                                          <xsl:value-of select="quantity"/>
                                    </DIV>
                              </TD>
                        </TR>
                  </xsl:for-each>
            </TABLE>
      </xsl:template>
      <xsl:template match="date">
            <xsl:eval>formatDate(this.nodeTypedValue, "MMMM dd',' yyyy")</xsl:eval>
              at <xsl:eval>formatTime(this.nodeTypedValue, "hh:mm tt")</xsl:eval>
      </xsl:template>
      <xsl:template match="year">
            <xsl:if expr="this.nodeTypedValue &gt; 0"/>
            <xsl:eval>formatNumber(this.nodeTypedValue, "####0")</xsl:eval>
      </xsl:template>
      <!-- Start of Functions -->
      <xsl:script>
            <![CDATA[

    function custcount(node)
    {
      total = 0;
      prices = node.selectNodes("/fleet/customer");
      for (v = prices.nextNode(); v; v = prices.nextNode())
        total += 1;
      return formatNumber(total, "#") + "Nos.";
    }


    function averageQty(node)
    {
      total = 0;
      qty = node.selectNodes("/fleet/customer/quantity");
      count = qty.length;
      for (p = qty.nextNode(); p; p = qty.nextNode())
        total += p.nodeTypedValue;
      return formatNumber(total/count, "###,###") + "Nos";
    }

    function max1(node)
    {
      max = 0;
      qty = node.selectNodes("/fleet/customer/quantity");
      for (p = qty.nextNode(); p ; p = qty.nextNode())
            if (p.nodeTypedValue > max)
                  max= p.nodeTypedValue;
      return  (max + "Nos");
    }

    function min1(node)
    {
      min = 1000;
      qty = node.selectNodes("/fleet/customer/quantity");
      for (p = qty.nextNode(); p; p = qty.nextNode())
            if (p.nodeTypedValue < min)
                  min = p.nodeTypedValue;
      return (min + "Nos");
    }
   
  ]]>
      </xsl:script>
</xsl:stylesheet>

----------------------------------------------
fleet_schema.xml
<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
      <ElementType name="description"/>
      <ElementType name="custcode"/>
      <ElementType name="make"/>
      <ElementType name="model"/>
      <ElementType name="year" dt:type="fixed.14.4"/>
      <ElementType name="quantity" dt:type="fixed.14.4"/>
      <ElementType name="hummers" content="eltOnly">

            <group minOccurs="0" maxOccurs="1">
                  <element type="description"/>
            </group>
            <group minOccurs="1" maxOccurs="1">
                  <element type="customer"/>
            </group>
      </ElementType>

      <ElementType name="customer" content="eltOnly">
            <element type="custcode"/>
            <element type="make"/>
            <element type="model"/>
            <element type="year"/>
            <element type="quantity"/>
      </ElementType>
</Schema>
0
 
LVL 2

Expert Comment

by:udnimbalkar
ID: 6309229
Hello Friend ,
   good example for you.This you will like.
check it out.
  Regards,
   Umesh Nimbalkar
   udnimbalkar@hotmail.com

--------------------------------------
fleet.xml

<?xml:stylesheet type="text/xsl" href="customer.xsl"?>
<fleet xmlns="x-schema:fleet-schema.xml">
      <description>Fleet Details</description>
      <customer>
            <custcode>c0001</custcode>
            <make>Tata</make>
            <model>LPT1613</model>
            <year>1993</year>
            <quantity>10</quantity>
      </customer>
      <customer>
            <custcode>c0002</custcode>
            <make>Tata</make>
            <model>LPT407</model>
            <year>1997</year>
            <quantity>4</quantity>
      </customer>
      <customer>
            <custcode>c0001</custcode>
            <make>Ashok</make>
            <model>11.10</model>
            <year>1998</year>
            <quantity>8</quantity>
      </customer>
      <customer>
            <custcode>c0003</custcode>
            <make>Tata</make>
            <model>1613</model>
            <year>1997</year>
            <quantity>12</quantity>
      </customer>
      <customer>
            <custcode>c0004</custcode>
            <make>Ashok</make>
            <model>11.10</model>
            <year>2000</year>
            <quantity>1</quantity>
      </customer>
      <customer>
            <custcode>c0005</custcode>
            <make>Tata</make>
            <model>LPT1613</model>
            <year>1997</year>
            <quantity>15</quantity>
      </customer>
      <customer>
            <custcode>c0005</custcode>
            <make>Tata</make>
            <model>LPT1018</model>
            <year>1999</year>
            <quantity>1</quantity>
      </customer>
</fleet>
------------------------------------------
customers.xsl

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
      <xsl:template match="/">
            <HTML>
                  <HEAD>
                        <STYLE>
                            BODY {margin:0; background-color="ivory"}
                            .bg {font:8pt Verdana; background-color:red; color:#000000; text="#000000"}
                            H1 {font:bold 14pt Verdana; width:100%; margin-top:1em; color:"#8b0000"}
                            H4 {font:bold 10pt Verdana; width:100%; margin-left:1em; color:"#8b0000"}
                            .row {bgColor="red" borderColorDark=#fcfcfc borderColorLight=#cccccc}
                            .header {borderColorDark:#f0f0f0 borderColorLight:#999999}
                            .new {background-color:#EEFFFD;}
                            .cheap {background-color:#FFDDDD;}
                    </STYLE>
                  </HEAD>
                  <!-- Sort Function -->
                  <SCRIPT>
                        <xsl:comment>
                              <![CDATA[
                            function sort(field)
                            {
                              sortField.value = field;
                              listing.innerHTML = source.documentElement.transformNode(stylesheet);
                            }



                        ]]>
                        </xsl:comment>
                  </SCRIPT>
                  <!-- Window OnLoad Function -->
                  <SCRIPT for="window" event="onload">
                        <xsl:comment>
                              <![CDATA[
                          stylesheet = document.XSLDocument;
                          source = document.XMLDocument;
                          sortField = document.XSLDocument.selectSingleNode("//@order-by");
                        ]]>
                        </xsl:comment>
                  </SCRIPT>
                  <!-- Start of HTML Body -->
                  <BODY>
                        <H1 align="center">
                              <xsl:value-of select="fleet/description"/>
                        </H1>
                        <p/>
                        <DIV id="listing">
                              <xsl:apply-templates select="fleet"/>
                        </DIV>
                        Total customers: <B>
                              <xsl:eval>custcount(this)</xsl:eval>
                        </B>
                        <BR/>
                        Average Vehicles: <B>
                              <xsl:eval>averageQty(this)</xsl:eval>
                        </B>
                        <BR/>
                        Max Vehicles: <B>
                              <xsl:eval>max1(this)</xsl:eval>
                        </B>
                        <BR/>
                        Minimum Vehicles: <B>
                              <xsl:eval>min1(this)</xsl:eval>
                        </B>
                        <BR/>
                        <BR/>
                  </BODY>
                  <!-- End of HTML Body -->
            </HTML>
      </xsl:template>
      <!-- Start of Templates -->
      <xsl:template match="fleet">
            <TABLE border="1" borderColor="white" cellPadding="2" cellSpacing="1" valign="TOP" align="center">
                  <TR bgColor="#cccccc" borderColorDark="#fcfcfc" borderColorLight="#999999">
                        <TD width="100">
                              <DIV onClick="sort('custcode')">Customer Code</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('make')">Make</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('model')">Model</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('year')">Year of Mfg.</DIV>
                        </TD>
                        <TD width="80">
                              <DIV onClick="sort('quantity')">Quantity</DIV>
                        </TD>
                  </TR>
                  <xsl:for-each select="customer" order-by="custcode">
                        <TR bgColor="#f0f0f0" borderColorDark="#fcfcfc" borderColorLight="#cccccc">
                              <!-- highlight Tata models -->
                              <xsl:for-each select="make">
                                    <xsl:if expr="this.nodeTypedValue == 'Tata'">
                                          <xsl:attribute name="class">new</xsl:attribute>
                                    </xsl:if>
                              </xsl:for-each>
                              <TD>
                                    <DIV>
                                          <xsl:value-of select="custcode"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row">
                                          <xsl:value-of select="make"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row">
                                          <xsl:value-of select="model"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV class="row" STYLE="text-align:center">
                                          <xsl:apply-templates select="year"/>
                                    </DIV>
                              </TD>
                              <TD>
                                    <DIV>
                                          <xsl:value-of select="quantity"/>
                                    </DIV>
                              </TD>
                        </TR>
                  </xsl:for-each>
            </TABLE>
      </xsl:template>
      <xsl:template match="date">
            <xsl:eval>formatDate(this.nodeTypedValue, "MMMM dd',' yyyy")</xsl:eval>
              at <xsl:eval>formatTime(this.nodeTypedValue, "hh:mm tt")</xsl:eval>
      </xsl:template>
      <xsl:template match="year">
            <xsl:if expr="this.nodeTypedValue &gt; 0"/>
            <xsl:eval>formatNumber(this.nodeTypedValue, "####0")</xsl:eval>
      </xsl:template>
      <!-- Start of Functions -->
      <xsl:script>
            <![CDATA[

    function custcount(node)
    {
      total = 0;
      prices = node.selectNodes("/fleet/customer");
      for (v = prices.nextNode(); v; v = prices.nextNode())
        total += 1;
      return formatNumber(total, "#") + "Nos.";
    }


    function averageQty(node)
    {
      total = 0;
      qty = node.selectNodes("/fleet/customer/quantity");
      count = qty.length;
      for (p = qty.nextNode(); p; p = qty.nextNode())
        total += p.nodeTypedValue;
      return formatNumber(total/count, "###,###") + "Nos";
    }

    function max1(node)
    {
      max = 0;
      qty = node.selectNodes("/fleet/customer/quantity");
      for (p = qty.nextNode(); p ; p = qty.nextNode())
            if (p.nodeTypedValue > max)
                  max= p.nodeTypedValue;
      return  (max + "Nos");
    }

    function min1(node)
    {
      min = 1000;
      qty = node.selectNodes("/fleet/customer/quantity");
      for (p = qty.nextNode(); p; p = qty.nextNode())
            if (p.nodeTypedValue < min)
                  min = p.nodeTypedValue;
      return (min + "Nos");
    }
   
  ]]>
      </xsl:script>
</xsl:stylesheet>

----------------------------------------------
fleet_schema.xml
<?xml version="1.0"?>
<Schema xmlns="urn:schemas-microsoft-com:xml-data" xmlns:dt="urn:schemas-microsoft-com:datatypes">
      <ElementType name="description"/>
      <ElementType name="custcode"/>
      <ElementType name="make"/>
      <ElementType name="model"/>
      <ElementType name="year" dt:type="fixed.14.4"/>
      <ElementType name="quantity" dt:type="fixed.14.4"/>
      <ElementType name="hummers" content="eltOnly">

            <group minOccurs="0" maxOccurs="1">
                  <element type="description"/>
            </group>
            <group minOccurs="1" maxOccurs="1">
                  <element type="customer"/>
            </group>
      </ElementType>

      <ElementType name="customer" content="eltOnly">
            <element type="custcode"/>
            <element type="make"/>
            <element type="model"/>
            <element type="year"/>
            <element type="quantity"/>
      </ElementType>
</Schema>
0
 

Author Comment

by:nitinafre
ID: 6325244
for Sachi,
  Your code includes asp, which is not my requirement. I was going through it. Since I don't have web server at my home PC, I can't able to run it but I had tried to understand your whole code. Generally I try to understand the code and then try it for my project. Well that will work but I don't want any asp call.
for udnimbalkar,
  I will try your code and let you know as again if it works I need to mould it as per my requirment. Just let it be open.
Thanx
Nitin
0
 

Author Comment

by:nitinafre
ID: 6329004
Umesh Nimbalkar,
     Your code did works but only when the xml is kept as it is and apply xsl to them. My question was I am displaying xml by transform node and I am not saving xml at all. The type of working in your code exactly I want but after transform node. If I transform node the xml, then in your code, document.XSLDocument didn't get. One time I can get the XMLDocument by xmldso.clone but not xsl. So in this given code only if you can tell how we can get XSLDocument after transform Node, then hope fully that will be sufficient.
Nitin
0
 

Author Comment

by:nitinafre
ID: 6336422
Any one can help me here. Is there any solution to my problem or not. Please help.
0
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 11

Expert Comment

by:sachiek
ID: 6341458
Hi there
  I will let u know soon..

Sachi

Else remain me again..

Sachi
0
 
LVL 27

Expert Comment

by:BigRat
ID: 6351429
Are you sending the xml directly from the server to the browser with mime type text/xml? And in the xml there is a reference to the stylesheet as an (effectively) http reference?
0
 

Author Comment

by:nitinafre
ID: 6352514
I am displaying the xml by Response.Write(xml.transformNode(xsl)) and not saving that xml at all. The example what Umesh had given requires bith xml and xsl file which I don't get after transforming.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 6353196
The problem is of course is that pure HTML ends up in the browser which could only be "sorted" with a lot of JavaScript hacking.

If you are ONLY supporting IE 5.x on an Intranet you could change the ASP page to just send the xml. In the xml you include a stylesheet reference and one could thereafter support all sorts of fancy XSL transformations. This would be a complete client-side solution.

The other alternative is to include an OnClick JavaScript event procedure on the <TH> element generated by the Server-Side XSL. This would re-send the ASP request with an extra parameter denoting which sort order you wanted. The server must of course regenerate the XML and this increases server load. However since almost all browsers support the OnClick event on <TH> you do have a cross browser solution.

So, how is it to be?

PS: When one clicks on the <TH> which is already the sort key, you toggle the sort order between ascending and descending)
0
 

Author Comment

by:nitinafre
ID: 6354389
The site is already supporting IE 5.x. So can you give me the code for that? I need a code for client side only as my requirement is for not to call server again. In the xsl, I get the xml file but how can I get the xsl, is the problem for me.
0
 

Author Comment

by:nitinafre
ID: 6378332
No Code???
0
 

Author Comment

by:nitinafre
ID: 6395329
Sachi,
    Did you find something. Does anyone can help me? Or should I delete this question.
0
 
LVL 2

Expert Comment

by:MicOfLZ
ID: 6396011
hi nitinafre

plz post your code. thnanks.

Cheers
MicOfLZ
0
 
LVL 27

Accepted Solution

by:
BigRat earned 50 total points
ID: 6398398
Sorry, Rat had customers. So here goes. This XSL sheet is to be put in the XML source and sent to the browser. It renders a table of data as follows :-

<result>
   <header>
      <col1 align="right">Header for column 1</col1>
      <col2 align="left">Header for column 2</col2>
      <col3>......</col3>
      ......
   </header>
   <data>
      <row>
         <col1>.....</col1>
         <col2>.....</col2>
         ..................
      </row>
      <row>
         ......
      </row>
       ....
   </data>
</result>

The column header say how the columns are to be aligned. One can extend this idea for other attributes. The basic idea is that the click on the <TH> element causes the script to modify the stylesheet.

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns:s="urn:schemas-microsoft-com:xml-data"
                xmlns:dt="urn:schemas-microsoft-com:datatypes"
                version="1.0">
<xsl:template match="/">
   <html>
   <link rel="stylesheet" href="BigRatStyle" type="text/css"></link>
   <head>
      <title><xsl:value-of select="/result/title"/></title>
      <script>
            <xsl:comment>
               <![CDATA[
                  var xslStylesheet = null;
                  var xmlSource = null;
                  var attribNode = null;
                  var whichNode = null;
                  var ascNode = null;
                  var sorText = null;
                  function sort(field)
                  {  /* sort out ascending or descending order if same field */
                     if(whichNode==field) {
                        /* same node */
                        ascNode=document.XSLDocument.selectSingleNode("//xsl:sort/@order");
                        if(ascNode.value=="ascending")
                          ascNode.value="descending";
                        else
                          ascNode.value="ascending";
                     }
                     /* sort out text or numeric sorting */
                     var locName,locNode;
                     locName="/result/header/" + field + "/@align";
                     locNode=document.XMLDocument.selectSingleNode(locName);
                     if((locNode!=null) && (locNode.value=="right"))
                        sortText="number"
                     else
                        sortText="text";
                     document.XSLDocument.selectSingleNode("//xsl:sort/@data-type").value=sortText;
                     /* get the node to put in the text */
                     /* store which field to sort */
                     attribNode.value = field;
                     whichNode=field;
                     /* transform the document */
                     Results.innerHTML =
                       xmlSource.documentElement.transformNode(xslStylesheet);
                  }
               ]]>
            </xsl:comment>
      </script>
      <script for="window" event="onload">
            <xsl:comment>
               <![CDATA[
                  xslStylesheet = document.XSLDocument;
                  xmlSource = document.XMLDocument;
                  attribNode =
                     document.XSLDocument.selectSingleNode("//xsl:sort/@select");
                  sort('col1');
               ]]>
            </xsl:comment>
         </script>
      </head>
      <body>
         <div id="Results"></div>
      </body>
   </html>
</xsl:template>
<xsl:template match="/result">
<table border="2">
<xsl:for-each select="/result/header/*">
   <xsl:element name="th">
      <xsl:attribute name="onclick">
        sort('<xsl:value-of select="local-name(.)"/>')
      </xsl:attribute>
      <xsl:value-of select="."/>
   </xsl:element>
</xsl:for-each>
<xsl:for-each select="/result/data/row">
   <xsl:sort select="col1" order="ascending" data-type="number"/>
   <tr>
      <xsl:for-each select ="./*">
         <xsl:element name="td">
            <xsl:if test="/result/header/*[local-name()=local-name(current())]/@align">
            <xsl:attribute name="ALIGN"><xsl:value-of select="/result/header/*[local-name()=local-name(current())]/@align"/></xsl:attribute>
            </xsl:if>
            <xsl:value-of select="."/>
         </xsl:element>
      </xsl:for-each>
   </tr>
</xsl:for-each>
</table>
</xsl:template>

</xsl:stylesheet>


HTH
0
 

Author Comment

by:nitinafre
ID: 6402519
BigRat,
    I will check it and let you know as I will required to change as per my requirement. It seems similar as of given by Umesh with little difference. Let me check.
Nitin
0
 

Author Comment

by:nitinafre
ID: 6423861
BigRat,
    The code doesn't work after transform node. It is the same one given by Umesh. The error is for document.XSLDocument and document.XMLDocument. After doing transformNode, the document doesn't get XSLDocument. This is the only problem for me. How can we get the XSLDocument after transformNode. So need solution for that. The code given by you is near about same as given by Umesh.
0
 
LVL 27

Expert Comment

by:BigRat
ID: 6433631
There is a problem with the code and it is NOT as you describe. I suspect that you have got something just not quite right. The problem with the code is that it produces a complete HTML page each time a header is clicked. When you then press the browser BACK button it can't find the page.

The correct way to do this is to basically keep the transform to produce the table and move the rest of the HTML outside. Two DOM objects global to the page hold the XML data :-

<HTML>
<SCRIPT>
var xmldata,xslsheet;

var attribNode = null;
var whichNode = null;
var ascNode = null;
var sorText = null;

function sort(field) {  /* sort out ascending or descending order if same field */
 if(whichNode==field) {
   /* same node */
   ascNode=xslsheet.selectSingleNode("//xsl:sort/@order");
  if(ascNode.value=="ascending")
     ascNode.value="descending";
  else
     ascNode.value="ascending";
  }
  /* sort out text or numeric sorting */
  var locName,locNode;
  locName="/result/header/" + field + "/@align";
  locNode=xmldata.selectSingleNode(locName);
  if((locNode!=null) && (locNode.value=="right"))
     sortText="number"
  else
     sortText="text";
  xslsheet.selectSingleNode("//xsl:sort/@data-type").value=sortText;
  /* get the node to put in the text */
  /* store which field to sort */
  attribNode.value = field;
  whichNode=field;
  /* transform the document */
  Results.innerHTML = xmldata.transformNode(xslsheet);
  }
}

function onLoad() {
   xmldata = new ActiveXObject('Microsoft.XMLDOM');
   xmldata.async = false;
   xslsheet = new ActiveXObject('Microsoft.XMLDOM');
   xslsheet.async = false;

   xmldata.load("......");
   xslsheet.load(".....");
   sort('col1');
}

</SCRIPT>
<BODY onload="onLoad()">

<DIV id="Results"></DIV>

</BODY>
</HTML>
0
 

Author Comment

by:nitinafre
ID: 6446828
BigRat,
    I am not storing xml file physically and after still trying your code, the onload function is not called. The reason might be that I am including lots of menus in that screen.
    Another thing is that I don't want to create object for xml and xsl. If you see my requirement at top, I already mentioned that I am not storing any physical file for xml and I have the problems only to get the xml and xsl file after transformNode. Atleast I cann't create object of ActiveXObject or anything.
    So onload is not called and if I use script tag, it gives error at the line where the object is created i.e. at first line itself. So sorry it is not working. Is there anymore tips?
Nitin
0
 

Author Comment

by:nitinafre
ID: 6498324
is there any one to help me?
0
 
LVL 27

Expert Comment

by:BigRat
ID: 6502212
Sorry I was on holiday.

The xsl style-sheet I posted is placed inside my XML data. The http server sends the XML data with a stylesheet link. The browser then fetches the stylesheet and transforms the data.

The problem with this approach is that if you follow a link (produced by the transformer from the data) and then press the back button the contents are lost (probably a bug in IE 5.5 or less) and so I prefer to create, load the data and transform it in an HTML page.

My code works.

I would suggest that you post a new question containing the code which does not work. Clearly taking examples from others and massaging them for your purpose is a source of error. I would have no objection to you deleting this question. It is getting a bit too long. Andd I have only a 33K modem here at home.
0
 

Author Comment

by:nitinafre
ID: 6704216
Sorry to accept it late. I already got the solution for sorting after transforming xml to html. Closing this question with a big thanx for your effort and support.
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now