Xsl转换的两种方式
来源:互联网 发布:脚本录制软件 编辑:程序博客网 时间:2024/06/05 02:21
Template-Driven Transformations
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD>
</HEAD>
<BODY>
<H1><xsl:value-of select="/books/book/title"/></H1>
<H3><xsl:value-of select="/books/book/author"/></H3>
<P>
<SPAN>Abstract:</SPAN>
<SPAN><xsl:value-of select="/books/book/abstract"/></SPAN>
</P>
</BODY>
</HTML>
</xsl:template>
</xsl:stylesheet>
Here, the style sheet expects certain data elements from a source document, which might look like this:
<?xml version="1.0"?>
<books>
<book>
<title>Synchronized Jamming</title>
<author>Kari Hensien</author>
<abstract>
A post modern flight of fancy.
</abstract>
</book>
</books>
Data-Driven Transformations
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<HTML>
<HEAD>
</HEAD>
<BODY>
<xsl:apply-templates />
</BODY>
</HTML>
</xsl:template>
<xsl:template match="book-review">
<P><xsl:apply-templates /></P>
</xsl:template>
<xsl:template match="title">
<SPAN style="font-weight:bold"><xsl:value-of select="."/></SPAN>
</xsl:template>
<xsl:template match="author">
<SPAN style="font-style:italic"><xsl:value-of select="."/></SPAN>
</xsl:template>
<xsl:template match="publisher">
<SPAN style="color:blue"><xsl:value-of select="."/></SPAN>
</xsl:template>
<xsl:template match="date">
<SPAN style="font-family:courier"><xsl:value-of select="."/></SPAN>
</xsl:template>
</xsl:stylesheet>
Sample
用数据驱动,针对某些section进行处理
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
exclude-result-prefixes="msxsl"
xmlns:ms="urn:anything"
>
<xsl:include href="CommonFunc.xslt"/>
<xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
<xsl:template match="Document">
<Document>
<Title>
<xsl:value-of select="Title"/>
</Title>
<Author>
<xsl:for-each select="Authors/Author">
<xsl:choose>
<xsl:when test="position() > 1 and position() != last()">
,
</xsl:when>
<xsl:when test="position() > 1 and position() = last()">
, and
</xsl:when>
</xsl:choose>
<xsl:value-of select="ByLine"/>
</xsl:for-each>
</Author>
<Date>
<xsl:value-of select ="PublishDate/@PublishMonthNameAbbr" /> <xsl:value-of select ="PublishDate/@PublishDayNumber" />, <xsl:value-of select ="PublishDate/@PublishFourDigitYear" /> <xsl:value-of select ="PublishDate/@PublishHour" />:<xsl:value-of select ="PublishDate/@PublishMinute" /> <xsl:value-of select ="PublishDate/@PublishAMPM" />
</Date>
<Body>
<xsl:apply-templates select="content/docBody"/>
</Body>
</Document>
</xsl:template>
<xsl:template match="Ticker">(<xsl:value-of select="."/>)</xsl:template>
</xsl:stylesheet>
<xsl:output omit-xml-declaration="yes" method="html" media-type="text/html" indent="no" encoding="iso8859-1"/>
<xsl:template match="/">
<script language="Javascript"><xsl:comment><![CDATA[
......
<xsl:apply-templates select="/Fund/Content/Analysis/RoleInPortfolio" />
......
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Take/Long">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Strategy">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Management">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Kudos/Kudo">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Concerns/Concern">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/RoleInPortfolio">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="Fund/Content/Analysis/Analyst/Bio">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ticker">
<a><xsl:attribute name="href"><xsl:choose>
<xsl:when test="/Fund/Footer/HostServer[. != 'online.morningstar.com']">
http://quote.morningstar.com/Switch.html?ticker=<xsl:value-of select="."/>
</xsl:when>
<xsl:otherwise>
/quote/Switch.html?ticker=<xsl:value-of select="."/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute><script>caseConvert('<xsl:value-of select="."/>')</script></a>
</xsl:template>
<xsl:template match="text()">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:template>
</xsl:stylesheet>
- Xsl转换的两种方式
- Android页面转换的两种方式
- xsl的转换
- Word文档转换成PDF的两种转换方式
- XML+XSL 与 HTML 两种方案的结合
- Object类型转换为String类型的两种方式
- c#两种方式 dataset 与byte[] 字节的转换
- json转换成time的两种方式
- Spark将RDD转换成DataFrame的两种方式
- Spark将RDD转换成DataFrame的两种方式
- xml与xsl的转换
- xml与xsl的转换
- SQL的两种类型转换方式
- String转换Long两种方式
- .net中xsl转换方式 XPathDocument > XmlDocument > XmlDataDocument
- 在服务器转换XSL的例子
- 两种“两数互换的方式”
- 谈谈CMS内容管理系统的两种方案:XSL+XML和HTML (一)
- 中午做的不好
- 在spring中使用声明型事务
- websphere笔记
- DB2和Websphere5.1环境应用安装手册
- 本人的Blog开通了
- Xsl转换的两种方式
- Oracle的实体化视图(MVIEW)的深入研究之一
- 用WinInet开发Internet客户端应用指南(转)
- error CS1024和error CS1025
- DataSourceControl(数据源控件)
- GRIDVIEW控件注意事项
- Oracle的实体化视图(MVIEW)的深入研究之二
- FFF
- .Net 中通用的FormatString格式符整理