怎样实现利用xslt把xml文件内容显示到html文件中?急!

jeall 2003-12-19 02:17:23
==============*.html源代码============
<HTML>
<Head>
<META http=equiv="Content-Type" Content="text/html;charset=gb2312">
<STYLE>
body { font-family:宋体; font-size:9pt;}
th { font-family:宋体; font-size:11pt; font-weight:bold;}
</STYLE>
<Script language="vbscript">
Option Explicit

Dim intRecordsPerPage '每个页面显示的记录数
intRecordsPerPage = 5 '每个页面显示的记录数,默认设定为5

' 更新显示页面的函数
Function window_onload()

' 显示设定的记录数
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
transform()
setPageCount()

End Function

' 进行XML-XSLT转换,并显示当前记录的一些信息
Function transform()

DisplayArea.innerHTML = Data.transformNode(Style.DocumentElement)
RecordsPerPage.Value = intRecordsPerPage

End Function

' 重新转换XML,并显示一个状态信息
Function redisplay(intPage)

Dim strDisplay
Dim intPageCount
Dim intRecordCount

' 保存状态信息
intPageCount = PageCount.innerHTML
intRecordCount = RecordCount.innerHTML
transform()
' 显示状态信息
PageCount.innerHTML = intPageCount
RecordCount.innerHTML = intRecordCount
CurrentPage.innerHTML = intPage

End Function

' 重新排序和显示
Function Sort(strField)

Dim sortField
Dim sortOrderAttribute
' 得到排序属性值
Set sortField = Style.XMLDocument.selectSingleNode("//xsl:sort/@select")
Set sortOrderAttribute = Style.XMLDocument.selectSingleNode("//xsl:sort/@order")

' 改变排序的方式
If sortField.Value = strField Or sortField.Value = "./*[0]" Then
If sortOrderAttribute.Value = "descending" Then
sortOrderAttribute.Value = "ascending"
Else
sortOrderAttribute.Value = "descending"
End If
Else
sortField.Value = strField
sortOrderAttribute.Value = "ascending"
End If

Set sortField = Nothing
Set sortOrderAttribute = Nothing

redisplay (CurrentPage.innerHTML)

End Function

...全文
153 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
正宗老冉 2003-12-20
  • 打赏
  • 举报
回复
<XML id='Data' SRC="YoungsoftStaff.xml"></XML>


YoungsoftStaff.xml
<Youngsoft北京总部员工>
<员工>
<用户账号>jeall</用户账号>
<姓名>佟丽娜</姓名>
<部门>产品研发部</部门>
<职位>程序员3-3</职位>
<电子邮件>tongln@hrxy.com</电子邮件>
</员工>
……
</Youngsoft北京总部员工>
jeall 2003-12-19
  • 打赏
  • 举报
回复
我是想把.xml与样式文件分开做!
正宗老冉 2003-12-19
  • 打赏
  • 举报
回复
htm文件中已包含XSL样式文件,且已定义读取XML数据节点(不限定的元素名称)的函数。
按需生成XML数据置入数据岛即可。

jeall 2003-12-19
  • 打赏
  • 举报
回复
=============11.xml========
<?xml version="1.0" encoding="gb2312"?>
<系统功能权限列表>
<系统功能权限>
<ID>1</ID>
<排序码>107</排序码>
<功能权限名称>数据源链接_冻结/解冻</功能权限名称>
<授让标志>5</授让标志>
<链接地址>/DS/DsForbid.aspx</链接地址>
<使用标志>True</使用标志>
<权限描述>绑定给DCmanager和Owner,不可授出,……</权限描述>
</系统功能权限>
......
</系统功能权限列表>
================
请问我的样式文件该怎样设置呢?
jeall 2003-12-19
  • 打赏
  • 举报
回复
' 重新设置每页的记录数
Function setRecordsPerPage()

If IsNumeric(RecordsPerPage.Value) Then
intRecordsPerPage = CInt(RecordsPerPage.Value)
window_onload
End If

End Function

' 显示页数信息
Function setPageCount()

Dim intTotalRecords

PageCount.innerHTML = getNumberOfPages(intTotalRecords)
RecordCount.innerHTML = intTotalRecords
CurrentPage.innerHTML = 1

End Function

' 计算总页数和总记录数
Function getNumberOfPages(intTotalRecords)

Dim intPages

intTotalRecords = Data.XMLDocument.selectNodes("/*/*").length
intPages = intTotalRecords / intRecordsPerPage
If InStr(intPages, ".") > 0 Then
intPages = CInt(Left(intPages, InStr(intPages, "."))) + 1
End If

getNumberOfPages = intPages

End Function

' “下一页”的处理
Function nextPage(intPage)

Dim strDisplay
Dim strDateRange

If CInt(CStr(intPage) * intRecordsPerPage) < Data.selectNodes("/*/*").length Then
intPage = CInt(intPage) + 1
Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]"
redisplay (intPage)
End If

End Function

' 处理“上一页”
Function previousPage(intPage)

Dim strDisplay
Dim strDateRange

If intPage > 1 Then
intPage = CInt(intPage) - 1
Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(" & intPage & ")"
Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(" & intPage & ")"
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() <= " & (CStr(intPage) * intRecordsPerPage) & " and position() > " & (CInt(intPage) - 1) * intRecordsPerPage & "]"
redisplay (intPage)
End If

End Function

' “第一页”的处理
Function FirstPage()

Style.XMLDocument.selectNodes("//@OnClick")(1).Value = "previousPage(1)"
Style.XMLDocument.selectNodes("//@OnClick")(2).Value = "nextPage(1)"
Style.XMLDocument.selectNodes("//xsl:for-each/@select")(1).Value = "./*[position() < " & intRecordsPerPage + 1 & " and position() > 0]"
transform()
setPageCount()

End Function

' “最末页”的处理
Function LastPage()

Dim intTotalPages
Dim intTotalRecords

intTotalPages = getNumberOfPages(intTotalRecords)
nextPage (intTotalPages - 1)

End Function
</Script>
</Head>
<body>
<p align="center" style="font-weight:bold;font-size:12pt;color:#0000FF;border-bottom:3px double red;padding-bottom:5px">华软新元北京总部全体员工</p>
<XML id='Data'>
<总部员工 xmlns="http://tempuri.org/YoungsoftStaff.xsd">

<员工>
<用户账号>guoyan</用户账号>
<姓名>郭燕</姓名>
<部门>行政部</部门>
<职位>外事与文案助理</职位>
<电子邮件>guoyan@dd.com</电子邮件>
</员工>
</总部员工>
</XML>
<XML id='Style'>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:user="http://lucky.myrice.com" version="1.0">
<msxsl:script language="VBScript" implements-prefix="user">
<![CDATA[
Function getName(node)
getName = node.Item(0).nodeName
End Function
]]>
</msxsl:script>

<xsl:template match="/">
<xsl:apply-templates select="/*"/>
</xsl:template>

<xsl:template match="/*">
<table width="100%" border="0" style="font-size:9pt">
<tr>
<td align="left"><b>第 <span id="CurrentPage"></span> 页 总 <span id="PageCount"></span> 页    共有 <span id="RecordCount"></span> 条记录</b></td>
<td align="right"><b>每页记录数:<input onblur="setRecordsPerPage()" id="RecordsPerPage" style="vertical-align:middle;height:15pt;width:30px"/></b></td>
<td align="right">
<span id="Paging">
<input type="button" OnClick="FirstPage()" value="首页"/>
<input type="button" OnClick="previousPage(1)" value="上页"/>
<input type="button" OnClick="nextPage(1)" value="下页"/>
<input type="button" OnClick="LastPage()" value="末页"/>
</span>
</td>
</tr>
</table>
<Table WIDTH="100%" BORDER="0" cellpadding="0" cellspacing="1" style="font-size:11pt" bgcolor="#0099ff">
<tr bgcolor="#FF6600" style="cursor: hand;padding:5px">
<xsl:for-each select="./*[1]/*">
<td align="center" bgcolor="#FF9900">
<xsl:attribute name="onclick">
Sort('<xsl:value-of select="user:getName(.)"/>')
</xsl:attribute>
<font color="#EEEEEE"><b><u><xsl:value-of select="user:getName(.)"/></u></b></font>
</td>
</xsl:for-each>
</tr>
<xsl:for-each select="./*[position() < 6 and position() > 0]">
<xsl:sort select="./*[1]" order="ascending"/>
<tr bgcolor="#FFCCFF">
<xsl:for-each select="./*">
<td> <xsl:value-of select="."/></td>
</xsl:for-each>
</tr>
</xsl:for-each>
</Table>
</xsl:template>
</xsl:stylesheet>
</XML>
<div id="DisplayArea"></div>
</body>
</HTML>
【作者】丁跃潮、张 涛 【出版社】北京大学出版社 【文件格式】 PDF 【ISBN】7301104626 【资料语言】简体文 【下载说明】 本资料为《XML实用教程》一书的PDF高清晰电子版,可用Adobe Reader7.0或兼容的阅读工具打开,强烈推荐Web技术爱好者下载!档案较大,分割为两部分,这是Part1。 【内容简介】 【内容简介】   可扩展标记语言XML是一种新的Web 开发辅助语言,利用它可以通过Internet/Intranet 进行信息的描述、交换和显示。本书是学习和应用XML 语言的实用教材,书阐述了XML 的基本概念、语法规则、文档类型定义(DTD)、Schema 结构、层叠样式单(CSS)、数据源对象(DSO)、文件转换(XSLT)、文档对象模型(DOM),还介绍了在Java、ASP 和.NET 以及电子商务环境下XML 的应用。为适应没有任何Web 编程知识的读者,还介绍了HTML 基础知识。本书内容由浅入深,全书13 章分初、、高级入门3 个层次,适合各类读者。在讲解基本概念和基础知识的同时给出了大量实例。每章还包括了教学提示、教学目标、小结和习题,便于读者巩固所学的知识。   本书适合具有一定计算机基础知识的读者阅读,可作为计算机及相关专业本科Web 设计或XML 课程的教材,也可作为大专院校非计算机专业学习计算机基础的教学参考书和自学用书,还可供从事Web 应用软件设计的科研人员参考。

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧