http://shop.oreilly.com/product/9780596000530.do
http://shop.oreilly.com/product/9780596527211.do
http://forum.eviloctal.com/thread-40778-1-4.html
http://www.w3schools.com/xsl/xsl_transformation.asp
http://www.w3schools.com/xsl/xsl_w3celementref.asp
http://zvon.org/xxl/XSLTreference/Output/index.html
http://www.w3.org/TR/xslt
1. 文件的根
<?xml version="1.0" encoding="Utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
</xsl:stylesheet>
<xsl:transform version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
2. 导入另一个xsl文件
<xsl:import href="Common.xsl"/>
3. 设置输出格式
<xsl:output method="text" encoding="Utf-8"/>
<xsl:output method="text" encoding="Shift_JIS"/>
4. 定义变量的值
<xsl:variable name="header">//////////////////////////////////////////////////////////////////////
// Ant により自動生成されたファイルです。
// 編集しないで下さい。
//////////////////////////////////////////////////////////////////////<xsl:text/>
</xsl:variable>
<xsl:variable name="typeMapping" select="document('TypeMapping.xml')/TypeMapping" />
5. 把变量的值写入输出
<xsl:value-of select="$header"/>
6. 声明节点匹配模板,设置输入的读取范围
<xsl:template match="Class">
</xsl:template>
<xsl:template match="Property[not(@collectionType)]">
</xsl:template>
<xsl:template match="Property[@collectionType = 'Array']">
</xsl:template>
<xsl:template match="Property[@collectionType = 'List']">
</xsl:template>
<xsl:template match="/">
7. 把普通文本写入输出
package
8. 读取节点然后写入输出
<xsl:value-of select="@package"/>
<xsl:value-of select="@comment"/>
<xsl:value-of select="@package"/>
<xsl:value-of select="@name"/>
<xsl:value-of select="translate(substring($name, 1, 1),
'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ')" />
<xsl:value-of select="substring($name, 2)" />
<xsl:value-of select="catalog/cd/title"/>
<xsl:for-each select="catalog/cd[artist='Bob Dylan']">
大小判断
= (equal)
!= (not equal)
< less than
> greater than
9. 条件输出
<xsl:if test="count(Property[@collectionType = 'List']) > 0">
</xsl:if>
<xsl:if test="@extends">
</xsl:if>
<xsl:if test="price > 10">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:if>
<xsl:choose>
<xsl:when test="string-length($definedType) > 0">
<!-- 定義型が見つかった場合はそれを使用する。 -->
<xsl:value-of select="$definedType"/>
</xsl:when>
<xsl:otherwise>
<!-- 定義型が見つからない場合は type属性をそのまま使用する -->
<xsl:value-of select="$type"/>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="$type='boolean'">
<xsl:text>is</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:text>get</xsl:text>
</xsl:otherwise>
</xsl:choose>
<xsl:choose>
<xsl:when test="price > 10">
<td bgcolor="#ff00ff">
<xsl:value-of select="artist"/></td>
</xsl:when>
<xsl:otherwise>
<td><xsl:value-of select="artist"/></td>
</xsl:otherwise>
</xsl:choose>
10. 嵌套调用模板
<xsl:apply-templates select="*"/>
<xsl:template match="cd">
<p>
<xsl:apply-templates select="title"/>
<xsl:apply-templates select="artist"/>
</p>
</xsl:template>
11. 注释
<!-- //////////////////////////////////////////////////////
// プロパティ (コレクション以外)
////////////////////////////////////////////////////// -->
12. 定义带参数的模板
<xsl:template name="getType">
<xsl:param name="type" />
</xsl:template>
13. 调用模板,把返回值赋值到另一个变量上
<xsl:variable name="getterPrefix">
<xsl:call-template name="getGetterPrefix">
<xsl:with-param name="type" select="@type"/>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="$getterPrefix"/>
14. 链接xml到xsl(XML语法)
<?xml-stylesheet type="text/xsl" href="cdcatalog.xsl"?>
放在<?xml version="1.0" encoding="ISO-8859-1"?>后,根前。
15. 循环遍历输出XML子树
<xsl:for-each select="catalog/cd">
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
<xsl:for-each select="catalog/cd">
<xsl:sort select="artist"/>
<tr>
<td><xsl:value-of select="title"/></td>
<td><xsl:value-of select="artist"/></td>
</tr>
</xsl:for-each>
for-each排序
16. 基本元素
apply-imports
应用已导入样式表的模板规则
apply-templates
把一个模板应用到当前元素或当前元素的子节点
attribute
添加属性
attribute-set
定义属性的具名集合
call-template
调用具名模板
choose
组合when和otherwise,表示多路条件测试
comment
创建注释节点
copy
创建当前节点的复制(不带子节点和属性)
copy-of
创建当前节点的复制(带子节点和属性)
decimal-format
定义number()函数转换数字到字符串时的格式
element
创建元素节点到输出文档
fallback
指定运行的可选代码,如果处理器不支持某个XSLT元素
for-each
循环指定的节点集下的所有节点
if
条件为真时应用指定的模板
import
导入另一个样式表的内容(被导入的具有较低优先级)
include
导入另一个样式表的内容(被导入的具有相同优先级)
key
声明在样式表中用于key()的具名键
message
写输出,用于报告错误
namespace-alias
在输出中替换命名空间
number
确定当前元素的整数位置并格式化数
otherwise
choose中的默认动作
output
定义输出文档的格式
param
定于局部或全局参数
preserve-space
定义保留空白的元素
processing-instruction
把处理操作写入输出
sort
排序输出
strip-space
定义移除空白的元素
stylesheet
定义样式表的根元素
template
可应用的规则,当指定节点匹配时
text
把字面值文本写入输出
transform
定义样式表的根元素
value-of
展开样式节点的值
variable
定义局部或全局变量
when
choose中的动作
with-param
定义传递进模板的参数
17. 基本内建XSLT函数
current()
返回当前节点
document()
访问外部XML文档的节点
element-available()
测试指定的元素是否被XSLT处理器支持
format-number()
把数转为字符串
function-available()
测试指定的函数是否被XSLT处理器支持
generate-id()
返回唯一标识指定节点的字符串
key()
返回<xsl:key>中用index指定的节点集
system-property()
返回系统属性
unparsed-entity-uri()
返回未解析入口的URI