使用XSLT元素:xsl:stylesheetxsl:templatexsl:apply-templatesxsl:value-ofxsl:keyxsl:outputxsl:paramxsl:with-paramxsl:ifxsl:for-eachxsl:attribute
使用XSLT和Xpath的函数:keyconcat
XML源文件:
<?xml version="1.0"?>
<questionaire>
<questions>
<question id="1" listref="agree" style="listbox">
<text>Astheglobalsecondandthirdeventsin
orderofspectators,theWorldandEuropeanchampionships
soccerdeservemorecoverageoninternationalnewssites.a.CNN.com.
</text>
<value>4</value>
</question>
<question id="2" listref="colors" style="checkbox">
<text>Whatareyourfavoritecolors?</text>
<value>2</value>
<value>4</value>
</question>
</questions>
<answer-lists>
<list name="colors">
<option id="1" name="red" />
<option id="2" name="yellow" />
<option id="3" name="green" />
<option id="4" name="red" />
<option id="5" name="red" />
</list>
<list name="agree">
<option id="1" name="strongly disagree" />
<option id="2" name="disagree" />
<option id="3" name="not sure" />
<option id="4" name="agree" />
<option id="5" name="strongly agree" />
</list>
</answer-lists>
</questionaire>
XSLT代码:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:key name="lists" match="//list" use="attribute::name"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="/">
<HTML>
<HEAD/>
<BODY>
<FORM>
<xsl:apply-templates select="questionaire/questions/question"/>
</FORM>
</BODY>
</HTML>
</xsl:template>
<xsl:template match="question">
<P>
<xsl:value-of select="child::text/text()"/>
<xsl:apply-templates select="key('lists', @listref)">
<xsl:with-param name="selected-values" select="value"/>
<xsl:with-param name="style" select="@style"/>
<xsl:with-param name="question_id" select="concat('q_',@id)"/>
</xsl:apply-templates>
</P>
</xsl:template>
<xsl:template match="list">
<xsl:param name="selected-values"/>
<xsl:param name="style">listbox</xsl:param>
<xsl:param name="question_id"/>
<xsl:if test="$style='checkbox'">
<xsl:for-each select="option">
<BR/>
<INPUT TYPE="checkbox" >
<xsl:attribute name="name">
<xsl:value-of select="$question_id"/>
</xsl:attribute>
<xsl:if test="$selected-values/text() = attribute::id">
<xsl:attribute name="CHECKED"/>
</xsl:if>
</INPUT>
<xsl:value-of select="@name"/>
</xsl:for-each>
</xsl:if>
<xsl:if test="$style='listbox'">
<BR/>
<SELECT >
<xsl:attribute name="name">
<xsl:value-of select="$question_id"/>
</xsl:attribute>
<xsl:for-each select="option">
<OPTION>
<xsl:if test="$selected-values/text() = attribute::id">
<xsl:attribute name="SELECTED"/>
</xsl:if>
<xsl:attribute name="value">
<xsl:value-of select="@id"/>
</xsl:attribute>
<xsl:value-of select="@name"/>
</OPTION>
</xsl:for-each>
</SELECT>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
分享到:
相关推荐
xslt-processor:不带本机库依赖项JavaScript XSLT处理器 开发技术 - 其它.zip
Answering the demand for an introductory book on XSLT processing, Ian Williams presents a clear, concise resource on XSLT concepts and methods and explains how and why XSLT relies on the XML Path ...
Xslt 解析 xml最好的文档, english name:A Guide to XML Transformations
XSLT使用的例子源码,XML与XSLT结合实现页面格式与数据的分离
xslt-转换 使用 XSLT 转换的 XML 文件转换 它包含一些有用的工具来转换 xml 文件。 使用以下参数运行 main 方法: files/input.xml files/prepdata.xsl files/output.xml COMPACT 1
xslt实例(实际例子) Export 3个 Import 3个 需要学习的可以下载来看,适用入门和中级学习!
使用npm安装xslt-processor :: npm install xslt-processor 在您的ES2015 +代码中,导入两个主要功能并应用它们: import { xsltProcess , xmlParse } from 'xslt-processor' // xmlString: string of xml file ...
XML内容管理应用程序的增长刺激了对XSLT和Xpath技能的要求.本入门教程提供了XSLT处理模型的基础,为开发者提供了重要的基本功. XSLT 是一种用于将 XML 文档转换为 XHTML 文档或其他 XML 文档的语言。 XPath 是一种...
XML内容管理应用程序的增长刺激了对XSLT和Xpath技能的要求.本入门教程提供了XSLT处理模型的基础,为开发者提供了重要的基本功. XSLT 是一种用于将 XML 文档转换为 XHTML 文档或其他 XML 文档的语言。 XPath 是一种...
这是个很好的,用xslt转换,修改xml的好例子!
此VSCode的XSLT / XPath扩展为XSLT 3.0和XPath 3.1提供了全面的语言支持。 屏幕截图显示了XSLT符号概述,问题报告和语法突出显示: 特征 XSLT 3.0 / XPATH 3.1 语法专门使用 内置代码诊断 与集成 XSLT语言对VSCode...
xslt的语法和例子, xpath语法和例子
xslt-visualizer XSLT软件可视化实验的大本营 (或并) 以下是可视化转换的步骤: ...使用一个命令运行所有三个步骤。 要查看结果(第4步),请在浏览器中打开build / example / visualized / exampl
主要用于练习xslt,初学者可以参考一下
我的XSLT沙箱。 例子 保存一个github-wiki页面,以便我可以在博客中使用它: $ curl -s " https://github.com/lindenb/jvarkit/wiki/Illuminadir " | \ xsltproc --html ./github2html.xsl - > file.html 将...
xslt-demo xslt-demo XSL的一些基本示例。
XSLT 元素使用说明
XSLT_TRANSFORM Bash,C#,Java,Perl,PHP,Powershell,Python,R,SAS和VBA中的XSLT脚本 要求: Bash-Unix终端 C#-标准/基础 Java-标准/基础 Perl-LibXML和LibXSLT模块 PHP-标准/基础 Powershell-Windows...
NULL 博文链接:https://sunny-java-163-com.iteye.com/blog/660580
4、testng-xslt的配置: (1) 解压testng-xslt-1.1压缩包: 把saxon-8.7.jar(testng-xslt-1.1\lib)放到在工程目录下创建一个Lib目录; 把testng-results.xsl (testng-xslt-1.1\src\main\resources)放到test-...