xml文件
<?xml version="1.0" encoding="utf-8" ?> <Paper Title="小寒考试系统" Name="大三历史期末考试" Start Time ="2008-1-28 09:00" Time="120" ScoreValue="100" Score="0"> <Student Name="小寒" Id="041124096"/> <Questions Title="单选题" ScoreValue="20" Count ="1" Score="0"> <DanXuan Id="1" Subject="历史" Chapter="第三章" D if ficulty="1" ScoreValue="20" Score="0"> <Content>诸葛亮姓什么?</Content> <Choices> <Choice Key ="1">诸</Choice> <Choice Key="2">诸葛</Choice> <Choice Key="3">诸葛亮</Choice> <Choice Key="4">亮</Choice> </Choices> <Answer>2</Answer> <StudentAnswer></StudentAnswer> </DanXuan> </Questions> <Questions Title="多选题" ScoreValue="20" Count="1" Score="0"> <DuoXuan Id="2" Subject="历史" Chapter="第三章" Difficulty="1" ScoreValue="20" Score="0"> <Content>三国是指那三国?</Content> <Choices> <Choice Key="1">魏国</Choice> <Choice Key="2">吴国</Choice> <Choice Key="3">辽国</Choice> <Choice Key="4">蜀国</Choice> </Choices> <Answer>1,2,4</Answer> <StudentAnswer></StudentAnswer> </DuoXuan> </Questions> <Questions Title="判断题" ScoreValue="20" Count="1" Score="0"> <PanDuan Id="3" Subject="历史" Chapter="第三章" Difficulty="1" ScoreValue="20" Score="0"> <Content>刘备建立了蜀国?</Content> <Choices> <Choice Key="0">0</Choice> <Choice Key="1">1</Choice> </Choices> <Answer>1</Answer> <StudentAnswer></StudentAnswer> </PanDuan> </Questions> <Questions Title="填空题" ScoreValue="20" Count="1" Score="0"> <TianKong Id="4" Subject="历史" Chapter="第三章" Difficulty="1" ScoreValue="20" Score="0"> <Content> <![CDATA[ 三国里的五虎上将是指关羽,$_4.1_$,$_4.2_$,$_4.3_$,赵云。 ]]> </Content> <Answers> <Answer Key="1">张飞</Answer> <Answer Key="2">魏延</Answer> <Answer Key="3">马超</Answer> </Answers> <StudentAnswers> <StudentAnswer Key="1"></StudentAnswer> <StudentAnswer Key="2"></StudentAnswer> <StudentAnswer Key="3"></StudentAnswer> </StudentAnswers> </TianKong> </Questions> <Questions Title=" 简答题 " ScoreValue="20" Count="1" Score="0"> <JianDa Id="5" Subject="历史" Chapter="第三章" Difficulty="1" ScoreValue="20" Score="0"> <Content>为什么诸葛亮没能统一三国?</Content> <Answer>因为魏国统一了三国。</Answer> <StudentAnswer></StudentAnswer> </JianDa> </Questions> </Paper>
xslt文件
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Trans for m" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:rules="http://www.netguy.cn/xslt" exclude-result-prefixes="rules msxsl"> <xsl:output method="html"/> <msxsl:script implements-prefix="rules" lang uage=" C# "> <![CDATA[ public static string ChangeTextBox(string content) { // Define a regular expression for repeated w ord s. Regex rx = new Regex(@"\$_\S\S\S_\$", RegexOptions.Compiled | RegexOptions.IgnoreCase); // Find matches. MatchCollection matches = rx.Matches(content); // Report on each match. foreach (Match match in matches) { string word = match.Value; content=content.Replace(word,"<input name=\""+word. Substr ing(2,word.Length-4)+"\" type=\"text\">"); } return content; } ]]> </msxsl:script> <xsl:template match="Paper"> <html xmlns="http://www.w3.org/1999/xhtml" > < head > <title> <xsl:value-of select="@Title"/> </title> </head> <body> <p class="Head"> <p class="Name"><xsl:value-of select="@Name"/></p> <p class="Info"> 姓名:<xsl:value-of select="Student/@Name"/> 学号:<xsl:value-of select="Student/@Id"/> 开考时间:<xsl:value-of select="@StartTime"/> 时间:<xsl:value-of select="@Time"/> 总分:<xsl:value-of select="@ScoreValue"/> </p> </p> <xsl:apply-templates select="Questions"/> </body> </html> </xsl:template> <xsl:template match="Questions"> <p class="Title"> <xsl:number format="I."/> <xsl:value-of select="@Title"/> <xsl:text>。(共</xsl:text> <xsl:value-of select="@Count"/> <xsl:text>题,</xsl:text> <xsl:value-of select="@ScoreValue"/> <xsl:text>分)</xsl:text> </p> <xsl:apply-templates select="DanXuan"/> <xsl:apply-templates select="DuoXuan"/> <xsl:apply-templates select="PanDuan"/> <xsl:apply-templates select="TianKong"/> <xsl:apply-templates select="JianDa"/> </xsl:template> <xsl:template match="DanXuan"> <p class="DanXuan"> <p class="Content"> <xsl:number format="1."/> <xsl:value-of select="Content"/> </p> <p class="Choices"> <ul> <xsl:for-each select="Choices/Choice"> <li> <xsl:number format="A."/> <input name="{http://www.cnblogs.com/@Id}" type="radio" value="{@Key}"/> <xsl:value-of select="."/> </li> </xsl:for-each> </ul> </p> </p> </xsl:template> <xsl:template match="DuoXuan"> <p class="DuoXuan"> <p class="Content"> <xsl:number format="1."/> <xsl:value-of select="Content"/> </p> <p class="Choices"> <ul> <xsl:for-each select="Choices/Choice"> <li> <xsl:number format="A."/> <input name="{http://www.cnblogs.com/@Id}" type="checkbox" value="{@Key}"/> <xsl:value-of select="."/> </li> </xsl:for-each> </ul> </p> </p> </xsl:template> <xsl:template match="PanDuan"> <p class="PanDuan" style=" width : 300 px"> <p class="Content" style=" float :left ;width:70%"> <xsl:number format="1."/> <xsl:value-of select="Content"/> </p> <p class="Choices" style="float :right ;width:25%"> <input name="{@Id}" type="radio" value="1"/>Y <input name="{@Id}" type="radio" value="0" />N </p> </p> </xsl:template> <xsl:template match="TianKong"> <p class="TianKong"> <xsl:number format="1."/> <xsl:value-of select="rules:ChangeTextBox(string(Content))" disable-output-esc api ng="yes"/> </p> </xsl:template> <xsl:template match="JianDa"> <p class="JianDa"> <p class="Content"> <xsl:number format="1."/> <xsl:value-of select="Content"/> </p> <p class="Input"> <textarea name="{@Id}" cols="70" rows="8"></textarea> </p> </p> </xsl:template> </xsl:stylesheet>
生成html
<html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>小寒考试系统</title> </head> <body> <div class="Head"> <div class="Name">大三历史期末考试</div> <div class="Info"> 姓名:小寒 学号:041124096 开考时间:2008-1-28 09:00 时间:120 总分:100</div> </div> <div class="Title" xmlns="">I.单选题。(共1题,20分)</div> <div class="DanXuan" xmlns=""> <div class="Content">1.诸葛亮姓什么?</div> <div class="Choices"> <ul> <li>A.<input name="1" type="radio" value="1">诸</li> <li>B.<input name="1" type="radio" value="2">诸葛</li> <li>C.<input name="1" type="radio" value="3">诸葛亮</li> <li>D.<input name="1" type="radio" value="4">亮</li> </ul> </div> </div> <div class="Title" xmlns="">II.多选题。(共1题,20分)</div> <div class="DuoXuan" xmlns=""> <div class="Content">1.三国是指那三国?</div> <div class="Choices"> <ul> <li>A.<input name="2" type="checkbox" value="1">魏国</li> <li>B.<input name="2" type="checkbox" value="2">吴国</li> <li>C.<input name="2" type="checkbox" value="3">辽国</li> <li>D.<input name="2" type="checkbox" value="4">蜀国</li> </ul> </div> </div> <div class="Title" xmlns="">III.判断题。(共1题,20分)</div> <div class="PanDuan" style="width:300px" xmlns=""> <div class="Content" style="float:left;width:70%">1.刘备建立了蜀国?</div> <div class="Choices" style="float:right;width:25%"><input name="3" type="radio" value="1">Y <input name="3" type="radio" value="0">N </div> </div> <div class="Title" xmlns="">IV.填空题。(共1题,20分)</div> <div class="TianKong" xmlns="">1. 三国里的五虎上将是指关羽,<input name="4.1" type="text">,<input name="4.2" type="text">,<input name="4.3" type="text">,赵云。 </div> <div class="Title" xmlns="">V.简答题。(共1题,20分)</div> <div class="JianDa" xmlns=""> <div class="Content">1.为什么诸葛亮没能统一三国?</div> <div class="Input"><textarea name="5" cols="70" rows="8"></textarea></div> </div> </body> </html>
以上是使用xlst将xml转换html的示例代码的详细内容。更多信息请关注PHP中文网其他相关文章!

一、XML外部实体注入XML外部实体注入漏洞也就是我们常说的XXE漏洞。XML作为一种使用较为广泛的数据传输格式,很多应用程序都包含有处理xml数据的代码,默认情况下,许多过时的或配置不当的XML处理器都会对外部实体进行引用。如果攻击者可以上传XML文档或者在XML文档中添加恶意内容,通过易受攻击的代码、依赖项或集成,就能够攻击包含缺陷的XML处理器。XXE漏洞的出现和开发语言无关,只要是应用程序中对xml数据做了解析,而这些数据又受用户控制,那么应用程序都可能受到XXE攻击。本篇文章以java

如何用PHP和XML实现网站的分页和导航导言:在开发一个网站时,分页和导航功能是很常见的需求。本文将介绍如何使用PHP和XML来实现网站的分页和导航功能。我们会先讨论分页的实现,然后再介绍导航的实现。一、分页的实现准备工作在开始实现分页之前,需要准备一个XML文件,用来存储网站的内容。XML文件的结构如下:<articles><art

当我们处理数据时经常会遇到将XML格式转换为JSON格式的需求。PHP有许多内置函数可以帮助我们执行这个操作。在本文中,我们将讨论将XML格式转换为JSON格式的不同方法。

Pythonxmltodict对xml的操作xmltodict是另一个简易的库,它致力于将XML变得像JSON.下面是一个简单的示例XML文件:elementsmoreelementselementaswell这是第三方包,在处理前先用pip来安装pipinstallxmltodict可以像下面这样访问里面的元素,属性及值:importxmltodictwithopen("test.xml")asfd:#将XML文件装载到dict里面doc=xmltodict.parse(f

1.在Python中XML文件的编码问题1.Python使用的xml.etree.ElementTree库只支持解析和生成标准的UTF-8格式的编码2.常见GBK或GB2312等中文编码的XML文件,用以在老旧系统中保证XML对中文字符的记录能力3.XML文件开头有标识头,标识头指定了程序处理XML时应该使用的编码4.要修改编码,不仅要修改文件整体的编码,还要将标识头中encoding部分的值修改2.处理PythonXML文件的思路1.读取&解码:使用二进制模式读取XML文件,将文件变为

使用nmap-converter将nmap扫描结果XML转化为XLS实战1、前言作为网络安全从业人员,有时候需要使用端口扫描利器nmap进行大批量端口扫描,但Nmap的输出结果为.nmap、.xml和.gnmap三种格式,还有夹杂很多不需要的信息,处理起来十分不方便,而将输出结果转换为Excel表格,方面处理后期输出。因此,有技术大牛分享了将nmap报告转换为XLS的Python脚本。2、nmap-converter1)项目地址:https://github.com/mrschyte/nmap-

xml中node和element的区别是:Element是元素,是一个小范围的定义,是数据的组成部分之一,必须是包含完整信息的结点才是元素;而Node是节点,是相对于TREE数据结构而言的,一个结点不一定是一个元素,一个元素一定是一个结点。

Scrapy是一款强大的Python爬虫框架,可以帮助我们快速、灵活地获取互联网上的数据。在实际爬取过程中,我们会经常遇到HTML、XML、JSON等各种数据格式。在这篇文章中,我们将介绍如何使用Scrapy分别爬取这三种数据格式的方法。一、爬取HTML数据创建Scrapy项目首先,我们需要创建一个Scrapy项目。打开命令行,输入以下命令:scrapys


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

AI Hentai Generator
免费生成ai无尽的。

热门文章

热工具

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

mPDF
mPDF是一个PHP库,可以从UTF-8编码的HTML生成PDF文件。原作者Ian Back编写mPDF以从他的网站上“即时”输出PDF文件,并处理不同的语言。与原始脚本如HTML2FPDF相比,它的速度较慢,并且在使用Unicode字体时生成的文件较大,但支持CSS样式等,并进行了大量增强。支持几乎所有语言,包括RTL(阿拉伯语和希伯来语)和CJK(中日韩)。支持嵌套的块级元素(如P、DIV),

禅工作室 13.0.1
功能强大的PHP集成开发环境

Atom编辑器mac版下载
最流行的的开源编辑器

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。