xml| Client | display
By passing parameters to the XSL + data island mode, the display of the sub frame of the client's individual XML is implemented.
For less data XML data, you can use one download all the data, will display all to the client complete, in the following example, an XML file is displayed to the left and right two frames, the left side of the item, display the content on the right-hand side. Can be done locally without having to be explained by the server.
Critical: Passing parameters to an XSL template using the DOM object of MSXML
Environment: IE6 + Msxml3.0
Examples:
/*** Book.xml ***/
<?xml version= "1.0" encoding= "gb2312"?>
<?xml-stylesheet type= "text/xsl" href= "book.xsl"?>
<moonpiazza>
<book id= "1" >
< title > ASP based on XML. NET Development </title >
< pricing >42</Pricing >
< author >dan wahlin/Wang Baoliang </author >
</book>
<book id= "2" >
< title >xml application of UML modeling technology </title >
< pricing >32</Pricing >
< author >david carlson/Ivan Zhou Handsome Hou Yimong Shen Jin </author >
</book>
<book id= "3" >
< title > Limit programming Research </title >
< pricing >70</Pricing >
< author >giancarrio succi/michele marchesi/Zhanghui (translated) </author >
</book>
<book id= "4" >
< title >design patterns</title >
< pricing >38</Pricing >
< author >erich Gamma/richard Helm/ralph johnson/john vlissides</author >
</book>
</moonpiazza>
/*** book.xsl ***/
<?xml version= "1.0" encoding= "gb2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:template match= "/" >
<script language= "JavaScript" >
<xsl:comment>
<! [cdata[
var m_oxsl;
var m_sframeattr_left, M_sframeattr_main;
var m_sxmlfile, M_sxsltfile;
M_sxmlfile = "";
M_sxsltfile = "book_view.xsl"; Specifying an XSL file
function Window.onload ()
{
var Oxsldoc;
M_sframename_left = "Left_frame";
M_sframename_main = "Main_frame";
m_oxsl = new ActiveXObject ("MSXML2. xsltemplate.3.0 ");
Oxsldoc = new ActiveXObject ("MSXML2. freethreadeddomdocument.3.0 ");
Oxsldoc.async = false;
Oxsldoc.load (M_sxsltfile);
M_oxsl.stylesheet= Oxsldoc;
Initpage ();
}
function Initpage ()
{
Content.cols = "270,*";
Viewframe (M_sframename_left);
var shtmlstr = "Please select bibliography ...";
Eval (M_sframename_main + ". Document"). Open ("text/html", "gb2312");
Eval (M_sframename_main + ". Document"). Write (SHTMLSTR);
}
function Viewframe (p_sframename)
{
var Oxslproc;
var shtmlstr;
Oxslproc = M_oxsl.createprocessor ();
Oxslproc.input = XmlData;
Specify a parameter to display the left (or right) frame
Oxslproc.addparameter ("Framename_left", m_sframename_left);
Oxslproc.addparameter ("Framename_main", M_sframename_main);
Oxslproc.addparameter ("FrameName", p_sframename);
Oxslproc.transform ();
Shtmlstr = Oxslproc.output; Get the converted String
Eval (p_sframename + ". Document"). Open ("text/html", "gb2312");
Eval (p_sframename + ". Document"). Write (SHTMLSTR);
}
function ViewData (p_sdataid)
{
var Oxslproc;
var shtmlstr;
Oxslproc = M_oxsl.createprocessor ();
Oxslproc.input = XmlData;
Specify parameters to display data with ID P_sdataid
Oxslproc.addparameter ("Framename_left", m_sframename_left);
Oxslproc.addparameter ("Framename_main", M_sframename_main);
Oxslproc.addparameter ("FrameName", M_sframename_main);
Oxslproc.addparameter ("Dataid", P_sdataid);
Oxslproc.transform ();
Shtmlstr = Oxslproc.output; Get the converted String
Eval (M_sframename_main + ". Document"). Open ("text/html", "gb2312");
Eval (M_sframename_main + ". Document"). Write (SHTMLSTR);
}
]]>
</xsl:comment>
</SCRIPT>
<xml id= "XmlData" >
<xsl:copy-of select= "*"/>
</xml>
<frameset cols= "0,*" name= "Content" >
<frame name= "Left_frame" src= "About:blank"/>
<frame name= "Main_frame" src= "About:blank"/>
</frameset>
</xsl:template>
</xsl:stylesheet>
/*** book_view.xsl ***/
<?xml version= "1.0" encoding= "gb2312"?>
<xsl:stylesheet version= "1.0" xmlns:xsl= "Http://www.w3.org/1999/XSL/Transform" >
<xsl:param name= "Framename_left" select= "Left_frame_null"/>
<xsl:param name= "Framename_main" select= "Main_frame_null"/>
<xsl:param name= "FrameName" select= "" "/>
<xsl:param name= "Dataid" select= "" "/>
<xsl:template match= "/" >
<style type= "Text/css" >
Body
{
font-size:9pt;
}
Td
{
font-size:9pt;
}
a{
font-size:9pt;
}
</style>
<xsl:choose>
<xsl:when test= "$frameName = $frameName _left" >
<xsl:call-template name= "Left_frame"/>
</xsl:when>
<xsl:when test= "$frameName = $frameName _main" >
<xsl:call-template name= "Main_frame"/>
</xsl:when>
</xsl:choose>
</xsl:template>
<xsl:template name= "Left_frame" >
<xsl:for-each select= "Moonpiazza/book" >
<xsl:element name= "a" >
<xsl:attribute name= "href" >
Javascript:parent.viewData (<xsl:value-of select= "@ID"/>);
</xsl:attribute>
<xsl:value-of select= "title"/>
</xsl:element>
<br/>
</xsl:for-each>
</xsl:template>
<xsl:template name= "Main_frame" >
<xsl:choose>
<xsl:when test= "$DataID!=" ">
<table border= "1" width= ">"
<xsl:for-each select= "moonpiazza/book[@ID = $DataID]/*" >
<tr>
<TD width= "><xsl:value-of" select= "name ()"/></td>
<td><xsl:value-of select= "."/></td>
</tr>
</xsl:for-each>
</table>
</xsl:when>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>