xsl对replace函数的支持不是很好,在1.0不好用,2.0也不好用。
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
<catalog>
<cd>
<title>/s/abc/s/cdcc</title>
<artist>Bob Dylan</artist>
<country>USA</country>
<company>Columbia</company>
<price>10.90</price>
<year>1985</year>
</cd>
<cd>
<title>Empire Burlesquebbb</title>
<artist>Bob Dylanbbb</artist>
<country>USAbbb</country>
<company>Columbiabbb</company>
<price>10.90bbb</price>
<year>1985bbb</year>
</cd>
</catalog>
<!--将title中的字符串/s/替换成/cl/,全局替换-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:variable name="titleInfo" select="title"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="$titleInfo"/>
<xsl:with-param name="replace" select="'/s/'"/>
<xsl:with-param name="by" select="'/cl/'"/>
</xsl:call-template>
</td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="string-replace-all">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:call-template name="string-replace-all">
<xsl:with-param name="text" select="substring-after($text,$replace)"/>
<xsl:with-param name="replace" select="$replace"/>
<xsl:with-param name="by" select="$by"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
<!--将title中的字符串/s/替换成/cl/,只替换一次-->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My CD Collection</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th align="left">Title</th>
<th align="left">Artist</th>
</tr>
<xsl:for-each select="catalog/cd">
<tr>
<td>
<xsl:variable name="titleInfo" select="title"/>
<xsl:call-template name="string-replace-once">
<xsl:with-param name="text" select="$titleInfo"/>
<xsl:with-param name="replace" select="'/s/'"/>
<xsl:with-param name="by" select="'/cl/'"/>
</xsl:call-template>
</td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
<xsl:template name="string-replace-once">
<xsl:param name="text"/>
<xsl:param name="replace"/>
<xsl:param name="by"/>
<xsl:choose>
<xsl:when test="contains($text,$replace)">
<xsl:value-of select="substring-before($text,$replace)"/>
<xsl:value-of select="$by"/>
<xsl:value-of select="substring-after($text,$replace)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
引用
http://zh-cn.w3support.net/index.php?db=so&id=1069092
分享到:
相关推荐
本文相关代码,解压为一个eclipse工程 博文链接:https://capslk.iteye.com/blog/457347
由于Netscape对XML的支持比较弱,因此,要实现跨平台的数据交换,数据的处理必须在服务器端进行。要编辑XML文档,首先要做的事情就是怎样把这些数据提取并显示给访问者,XSL为我们显示 XML文件提供了一个很好的解决...
(1)使用ms:script嵌入XSL实现,但要求XML解析器必须是MS的。 (2)使用纯XSL模板来实现。 当然,使用第(1)种方法有个好处就是可以充分利用javascript强大的字符串处理功能,例如还可以使用正则表达式。这里使用了一个...
NULL 博文链接:https://gogo1217.iteye.com/blog/1961276
XSL函数大全 XSL元素大全 常用的XPATH手册 XSL知识速查
XSL-FO 简介 XSL-FO 的简介。包括其概念和作用。 XSL-FO 文档 本章将解 XSL-FO 文档的结构。 XSL-FO 区域 本章讲解 XSL-FO 的区域模型(area model)。 XSL-FO 输出 本章讲解 XSL-FO 文档的输出元素(Output ...
针对于xml个人简历,附有xsl文档代码: <xsl:stylesheet version="1.0" xmlns:xsl=...<xsl:template match="/"> <html> <head> <title><xsl:value-of select="简历/个人简历/基本信息/姓名"/>XX的个人简历</title>
对xml+xsl实现分页排序的改进,使支持对所有数据进行排序 以往见过的利用xml+xsl来实现分页排序的基本都只能本页内排序,而不能对所有数据进行排序,究其原因,简单分析如下: xml+xsl分页原理:在xsl中,遍历节点...
Laravel开发-xsl-laravel-template-engine Laravel的XSLT模板引擎。基于Krowinski/Laravel XSLT。
比较有用的关于xml的命令, xsl:import元素 xsl:import元素用于导入外部的样式单,也是一个顶级元素。...<xsl:template match=”node”> <xsl:apply-impotres/> </xsl:template> ……… </xsl:stylesheet>
用xml 和 xsl 快速web实现二维统计报表 : 1、读取统计数据生成xml。 2、编写适合解析 xml 数据转化为报表的 XSL 附件是具体用例
XSL速查XSL速查XSL速查XSL速查XSL速查XSL速查
我之前上传的jmeter.results.shanhe.me.xsl没有这个功能强大和实用。 功能如下: 1.增加了格式化JSON响应值的功能。 格式化后有颜色区分并缩进,但是没有复杂的按钮控制,及伸缩展开(后续也可以加)。 2.左上角增加...
一个跨浏览器的解决方法 ...在服务器上进行XSL转换正在成为未来Internet信息服务器工作任务的一个主要部 分,同时我们将看到专用浏览器市场的发展,如:Braille、有声网络、网络打印 机、手持PC、移动电话等。
BasicXSLT在GitHub上有一个新主页,网址为:... 允许将多个XSL样式表链接在一起,并允许在每个样式表上设置参数和输出属性。 记住配置信息并提供定时号。
xml +js+xsl 实现无限极菜单
xml+xsl+css html网页 xml+xsl+css html网页 xml+xsl+css html网页 xml+xsl+css html网页 xml+xsl+css html网页 xml+xsl+css html网页
XML+xsl讲XML文档的内容用xsl建表。
XSL 官方文档XSL 官方文档XSL 官方文档XSL 官方文档XSL 官方文档XSL 官方文档XSL 官方文档