XSLT常用元素及属性

XSLT 语言:
   XSL/XSLT是一种xml语言转换。XSL(eXtensible Style sheet Language)是XML的样式表语言。
   它包含三个部分:转换XML文档以及定义输出XML部分以及格式化XML文档;
   包含了三种语言:XSLT、XPath和XSL格式对象。其中XSLT最为重要,它用于将XML文档转换成另一个XML文档或另一种类型的文档。也就是能将一个XML文档转换成浏览器能识别的一种格式。
   XSL转换过程:XSLT用XPath来获取源XML文档中一部分需要的数据,经过XSL语言转换后或是直接将数据输出。
   支持XSL的浏览器:用XSL来处理一个XML文档,需要一个带有XSL引擎的XML解析器。目前IE5或以上版本是符合这一条件的唯一浏览器。
XML范例
<Book>
  <CateGory_B1>文学</CateGory_B1>
  <CateGory_B2>社会科学</CateGory_B2>
  <CateGory_B3>工业技术</CateGory_B3>
  <CateGory_B4>综合性图书</CateGory_B4>
</Book>
元素:
1. 创建模板,匹配元素"CateGory_B2"的值
   <xsl:template  match="/Root/CateGory_B2"></xsl:template>
2. 调用命名模板传参,call-template的使用前提是必须有一个命名的模板,required设置参数为必须被使用。
   <xsl:template name="group2">                                                                           <xsl:param name="title" required="yes"> ...
   </xsl:template> 
   <xsl:call-template name="group2">
        <xsl:with-param name="title" select="/Root/CateGory_B4"/>... 
   </xsl:call-template> 
3. 创建一个元素到输出文档
   <xsl:element name="CateGory_B5">...</element>
4. 创建一个值为"CodeValue"的Code属性
    <xsl:attribute name="Code">CodeValue</xsl:attribute> 
5. 创建一个属性集合
    <xsl:attribute-set name="AttributeCollection">    
       <xsl:attribute name="Code1">Red</xsl:attribute>
       <xsl:attribute name="Code2">Bule</xsl:attribute>
       <xsl:attribute name="Code3">Yellow</xsl:attribute>
    </xsl:attribute-set>
6. 定义一个值为"文学"的变量,变量的使用
    <xsl:variable name="variable1" select="Root/CateGory_B1"/></xsl:variable>
7. 条件选择给变量variable2赋值。otherwise相当于C#switch中的default。
    <xsl:variable name="variable2">    
     <xsl:choose>
      <xsl:when test="@variable1= "'文学'">
         <xsl:value-of select="'文学作品'"/>
      <xsl:when>
      <xsl:when test="@variable1= "'工业技术'">
         <xsl:value-of select="'文学作品'"/>
     <xsl:when>
     <xsl:otherwise> 
         <xsl:value-of select="'经济科学'"/>
     </xsl:otherwise>
     </xsl:choose>
    </xsl:variable>
8. 指定节点集中循环。找出节点下所有名为"CateGory_B3"的元素值
    <xsl:for-each select="/Root/">
     <xsl:value-of select="CateGory_B3"/>
    </xsl:for-each>

特殊字符的实体编码:
   &lt;
   &gt;
‘   &apos;
“   &quot;
   &amp;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值