XSL 指扩展样式表语言(EXtensible Stylesheet Language),XSLT 指 XSL 转换

引用xsl样式文件

<?xsl:stylesheet type="text/xsl" href="path"?>

声明
<xsl:stylesheet version=“1.0” xmlns:xsl=“www.w3.org/1999/XSL/Transform”>
or
<xsl:Transform version=“1.0” xmlns:xsl=“www.w3.org/1999/XSL/Transforn”>

模板

XSL 样式表由一个或多套被称为模板(template)的规则组成。
每个模板含有当某个指定的节点被匹配时所应用的规则。

元素名 描述
xsl:template 定义模板
xsl:for-each 遍历选定节点的子节点
xsl:value-of 选中某个节点的值
xsl:sort 对结果进行排序
xsl:if 对节点值进行条件测试
xsl:choose 结合xsl:when和xsl:otherwise对节点值进行多条件测试
xsl:apply-templates 把模板应用于当前节点或子节点中,select 属性指定要应用的节点

xsl:apply-templates的应用

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>Old cds</h2>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>
<xsl:template match="CD">
<p>
<xsl:apply-templates select="name"/>
<xsl:apply-templates select="time"/>
</p>
</xsl:template>

<xsl:template match="name">
<xsl:value-of select="."/>
</xsl:template>

<xsl:template match="time">
<xsl:value-of select="."/>
</xsl:template>

</xsl:stylesheet>

XSLT

相关文章:

  • 2021-10-20
  • 2021-05-25
  • 2022-12-23
  • 2022-12-23
  • 2021-09-05
  • 2021-07-05
  • 2021-05-28
  • 2021-10-13
猜你喜欢
  • 2021-08-21
  • 2021-10-05
相关资源
相似解决方案