zoukankan      html  css  js  c++  java
  • XSLT知识总结(转)

    <!--[if !supportLists]-->2       <!--[endif]-->XSLT元素
    <!--[if !supportLists]-->一、            <!--[endif]-->xsl:If:简单的条件判断元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

          <xsl:if

      test = boolean-Expression>

    </xsl:if>

            部分属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->Test

    一个逻辑表达式,如果为真则执行xsl:if的content所表达的操作,如果为false则不致性任何操作。

    逻辑表达式可以为一个脚本判断语句,也可以为源数据中的某个节点或者属性,如果为源数据中的节点或者属性的话,则xslt执行引擎自动会把节点或者属性的值转换为Boolean值,再进行判断。

    必选

    <!--[if !supportLists]-->3、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素: xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    <!--[if !supportLists]-->二、            <!--[endif]-->xsl:for-each:对一个模板规则进行循环执行元素,也就是说对一个节点集合中的每一个节点进行循环处理。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:for-each

      select = Expression>

    </xsl:for-each>

              部分元素说明

    <!--[if !supportLists]-->2、  <!--[endif]-->select:

    一个xpath表达式,用来在当前上下文中选择一系列满足条件的源数据节点,然后对每一个节点按照content模板规则进行处理。

    <!--[if !supportLists]-->3、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:xsl:apply-imports, xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:number, xsl:processing-instruction, xsl:sort, xsl:text, xsl:value-of, xsl:variable

    <!--[if !supportLists]-->三、            <!--[endif]-->xsl:choose ,  xsl:when ,  xsl:otherwise:多条件判断组合元素

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:choose>

      <xsl:when

          test = boolean-Expression>

    </xsl:when>

    <xsl:otherwise>

    </xsl:otherwise>

    </xsl:choose>

              部分元素说明

    <!--[if !supportLists]-->2、  <!--[endif]-->test:

    逻辑判断表达式,参考xsl:if中的test属性说明。

    <!--[if !supportLists]-->3、  <!--[endif]-->备注:

    Xsl:choose、xsl:when以及xsl:otherwise的作用类似程序设计语言中的switch、case以及default的作用。其中的xsl:when可以多次出现,而xsl:otherwise则是可以选择的,而且最多可以出现一次。

    <!--[if !supportLists]-->四、            <!--[endif]-->xsl:value-of:获取选择节点的值作为文本插入到输出信息中。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:value-of

      select = Expression

      disable-output-escaping = "yes" | "no"

    </xsl:value-of>

    部分元素说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->select:

    一个表达式。

    如果该表达式表示当前上下文中的一个节点时,则将该节点转化为一个字符串(获取该节点的值)输出。

    如果该表达式表示为当前上下文中节点集合的话则将该集合中的第一个节点转化为一个字符串输出。

    该表达式也可以为一个脚本语句或者一个常量,则系统自动会计算该语句的结果,并将结果转换为字符串输出。

    <!--[if !supportLists]-->3、  <!--[endif]-->disable-output-escaping:

    输出信息是否为一个转义符,默认为no, 如果为yes,则将select中的内容作为转义符进行输出,例如:<xsl:value-of disable-output-escaping="yes" select="string('&lt;')"/>则会输出一个”<”来。

    <!--[if !supportLists]-->4、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:无。

    <!--[if !supportLists]-->五、            <!--[endif]-->xsl:template:定义一个可以重用的数据转换规则模板元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:template

      name= Qname

      match = Pattern

      priority = number

      mode = QName

    </xsl:template>

    部分属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->name:

    模板规则的名称,应该全局唯一的。如果一个模板转换规则具有名称,那么它能但是一般不需要再有”match”属性。Name属性一般于<xsl:call-template>配合使用。

    <!--[if !supportLists]-->3、  <!--[endif]-->match:

    一个xpath表达式,确定在什么情况下使用该模板转换规则。如果没有”name”属性的话,那么”match”属性是必须的。

    <!--[if !supportLists]-->4、  <!--[endif]-->priority:

    模板规则的优先级,如果具有多个相同”match”的模板的话,那么<xsl:apply-templates>则依据模板转换规则的优先级进行筛选。如果没有显式指定优先级,则处理器会为模板计算一个默认值。由处理器指定的默认优先级范围是从 -0.5 到 +0.5。基本上,模式越特殊,其默认优先级就越高。由于范围是从 -0.5 到 +0.5,因此如果显式指定一个模板的优先级为 1,就总会超过默认优先级。

    <!--[if !supportLists]-->5、  <!--[endif]-->mode:

    模板规则的模式值。一般”mode”于<xsl:apply-templates>的”mode”配合使用:如果<xsl:apply-templates>具有”mode”属性,那么它仅仅从那些具有相同
    ”mode”值的模版规则中进行筛选;如果<xsl:apply-templates>没有”mode”属性的,那么它也仅仅从那些没有”mode”属性的模版规则中进行筛选。

    <!--[if !supportLists]-->6、  <!--[endif]-->元素信息:

    元素次数:无限制

    父元素: xsl:stylesheet, xsl:transform

    子元素: xsl:apply-imports, xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:number, xsl:param, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    <!--[if !supportLists]-->7、  <!--[endif]-->备注:

    <xsl:template>可以使用<xsl:param>子元素同<xsl:call-template>及<xsl:apply-templates>的<xsl:with-param>子元素进行类似程序设计中的参数调用操作。

    <!--[if !supportLists]-->六、            <!--[endif]-->xsl:call-template::调用一个具有相同的”name”属性的模板转换规则的元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:call-template

      name = QName>

    </xsl:call-template>

    <!--[if !supportLists]-->2、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:xsl:with-param

    <!--[if !supportLists]-->3、  <!--[endif]-->备注:

    如果获得多个相同”name”属性的<xsl:template>的话则抛出一个错误。

    子元素<xsl:with-param>的使用方法参考<xsl:template>的备注信息部分。

    <!--[if !supportLists]-->七、            <!--[endif]-->xsl:apply-templates:根据每个选择节点的内容以及类型指导xslt解析器选择合适的模板转换规则<xsl:template>进行调用。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:apply-templates

      select = Expression

      mode = QName>

    </xsl:apply-templates>

    部分属性说明

    <!--[if !supportLists]-->2、  <!--[endif]-->select:

    一个xpath表达式,选择合适的节点集合然后分别再调用对应的<xsl:template>对节点进行数据转换处理。

    <!--[if !supportLists]-->3、  <!--[endif]-->mode:

    具体参考<xsl:template>的”mode”属性说明。

    <!--[if !supportLists]-->4、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素: xsl:sort, xsl:with-param

    <!--[if !supportLists]-->5、  <!--[endif]-->备注:

    如果一个节点具有多个<xsl:template>的话,那么根据<xsl:tempate>的优先级(”priority”属性)确定,如果具有多个相同的优先级的<xsl:template>的话则选择最后一个<xsl:template>。

    如果没有找到合适的<xsl:template>的话,那么xslt解析器自动把当前节点及其子节点的text连接起来并向目标数据进行输出,相当于调用<xsl:valueof    select =”.”/>。XSLT 定义了几个模板,它们默认生成到每个转换中(不管您是否显式提供)。这些模板被称为 XSLT 的内置模板。可能在 XML 文档中处理的每种类型的节点(元素、属性、处理指令、注释等等)都有一个内置模板。然而,这些内置模板的优先级可能最低,因此当用户提供的模板也匹配相同节点时就从不会使用它们(请参见上一个关于冲突解决的问题)。只有当不存在匹配特定节点的其他模板时才使用它们。

    可以采用<xsl:sort>对输出的节点集合进行排序。

    子元属<xsl:with-param>的使用说明参见<xsl:template>的备注部分。

    <!--[if !supportLists]-->八、            <!--[endif]-->xsl:param:参数元素

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:param

      name = QName

      select = Expression>

    </xsl:param>

    部分属性说明

    <!--[if !supportLists]-->2、  <!--[endif]-->Name:

    参数的名称,必须全局唯一,而且必选。参数的使用方式:$param-name。

    <!--[if !supportLists]-->3、  <!--[endif]-->Select:

    一个xpath表达式,从当前上下文中获取对应的节点元素,如果不存在对应的节点的话,那么param的默认值为空。如果select存在的话,那么<xsl:param〉的内容必须为空。

    <!--[if !supportLists]-->4、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素: xsl:stylesheet, xsl:template, xsl:transform

    子元素:xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    <!--[if !supportLists]-->5、  <!--[endif]-->备注:

    (1)参数的使用方式:$param-name

    (2)<xsl:param>的select属性与非空的内容不能够同时存在。

    (3)如果<xsl:param>具有”select”属性,那么这个属性的值必须是一个表达式,而且从该表达式计算得到的值必须是一个对象,否则这个参数的值为空。

    (4)<xsl:param>具有自己的作用域,作用域的范围由父元素决定。

    (5)<xsl:param>可以通过xslt解析器由外部设置值,具体使用方法可以参考System.Xml.Xsl.XsltArgumentList类的使用方法。

    (6)<xsl:param>可以与<xsl:with-param>搭配起来使用。

    <!--[if !supportLists]-->九、            <!--[endif]-->xsl:with-param:向一个<xsl:template>传递一个参数值。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方法:

    <xsl:with-param

      name = QName

      select = Expression>

    </xsl:with-param>

    <!--[if !supportLists]-->2、  <!--[endif]-->属性说明参考<xsl:param>

    <!--[if !supportLists]-->3、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素:xsl:apply-templates, xsl:call-template

    子元素:sl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable

    <!--[if !supportLists]-->十、            <!--[endif]-->xsl:variable:变量元素,将一个表达式和一个变量名称绑定在一起。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:variable

      name = QName

      select = Expression>

    </xsl:variable>

    <!--[if !supportLists]-->2、  <!--[endif]-->属性的使用方法以及作用与<xsl:param>完全一致,具体参见<xsl:param>

    <!--[if !supportLists]-->3、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素: xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:for-each, xsl:if, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:stylesheet xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素: xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    <!--[if !supportLists]-->4、  <!--[endif]-->备注:

    <xsl:param>与<xsl:variable>的使用方法以及作用都相同,但是有存在如下的区别:

    (1)<xsl:param>的使用场合较少(仅仅xsl:stylesheet, xsl:template, xsl:transform),而<xsl:variable>则使用场合较多。

    (2)<xsl:param>可以通过xslt解析器由外部设置其具体值,并且可以通过<xsl:with-param>在模板中修改其默认值,而<xsl:variable>则没有这种能力。

    <!--[if !supportLists]-->十一、    <!--[endif]-->xsl:import、xsl:include:导入外部转换模板元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:import  href = "uri-reference" />

    <xsl:include  href = "uri-reference"/>

    属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->href:

    被导入的xslt文件位置。

    <!--[if !supportLists]-->3、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素: xsl:stylesheet, xsl:transform

    子元素:无

    <!--[if !supportLists]-->4、  <!--[endif]-->备注:

    <!--[if !supportLists]-->              <!--[endif]-->import与include必须为顶层元素,如果import与include同时存在,那么import一定要在include前声明。

    <!--[if !supportLists]-->              <!--[endif]-->import与include的主要区别主要为:include与被导入的样式表中的模板处于完全相同的地位(具有相同的默认优先级),没有任何差别,但是import导入的模板则具有较低的默认优先级。

    <!--[if !supportLists]-->十二、    <!--[endif]-->xsl:apply-imports:优从插入的样式表中调用被重载的转换规则模版元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:apply-imports />

    <!--[if !supportLists]-->2、  <!--[endif]-->元素信息:

    出现次数:无限制

    父元素: xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:无

    <!--[if !supportLists]-->3、  <!--[endif]-->备注:

    Xslt解析器会优先从import的样式表查找符合条件的模版,如果import的样式表中不存在对应的模版,再从原样式表中查找符合条件的模版。

      

    <!--[if !supportLists]-->十三、    <!--[endif]-->xsl:copy、xsl:copy-of:拷贝源节点数据插入到目标数据中元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:copy  use-attribute-sets = QNames >

    </xsl:copy>

    <xsl:copy-of  select = Expression/>

    部分属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->use-attribute-sets:

    一个属性集合名称,或者一个空格分隔的多个属性名称。

    <!--[if !supportLists]-->3、  <!--[endif]-->select:

    一个xpath表达式,用来获取xsl:copy-of用来拷贝到目标数据中的部分。如果结算的结果为节点集合,那么copy-of会将这些节点及其该节点的所有属性以及子节点按照原顺序全部拷贝到目标数据中;如果计算结果为一个值,则将该值写入目标数据中。如果为非法的xpath表达式,则不作任何操作。

    <!--[if !supportLists]-->4、  <!--[endif]-->元素信息:

    xsl:copy:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    xsl:copy-of:

    出现次数:无限制

    父元素:xsl:attribute, xsl:comment, xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:processing-instruction, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:无

    <!--[if !supportLists]-->5、  <!--[endif]-->备注:

    (1)、xsl:copy:将在目标数据中创建一个与当前节点相同名称、数据类型、命名空间的节点,但是当前节点的文本信息、子节点、属性并不会自动拷贝到目标数据节点中去。

     (2)、xsl:copy-of:当其“select”属性结算结果为一个源数据中的一个节点或者节点集合的时候,它会将该节点或者节点集合及其属性以及子节点按照相同的顺序安全拷贝到目标数据中去。这也是xsl:copy-of与xsl:copy的主要区别,另外如果计算的结果为一个值得时候,它会把这个值输出到目标数据中去。

    <!--[if !supportLists]-->十四、    <!--[endif]-->xsl:sort:结点集合排序元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:sort

      select = string-Expression

      lang = { nmtoken }

      data-type = { "text" | "number" | QName }

      order = { "ascending" | "descending" }

      case-order = { "upper-first" | "lower-first" }

    />

    属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->select:

    一个xpath表达式,为节点选择排序使用的键(节点本身、子节点、属性或者其它相关节点),如果结算结果不为节点,则xsl:sort不起任何作用。

    <!--[if !supportLists]-->3、  <!--[endif]-->lang:

    排序使用的语言,不同的语言有不同的排序比较算法。

    <!--[if !supportLists]-->4、  <!--[endif]-->data-type:

    排序使用键对应节点的数据类型。

    <!--[if !supportLists]-->5、  <!--[endif]-->order:

    升序或者降序

    <!--[if !supportLists]-->6、  <!--[endif]-->case-order:

    字符串大小写处理方法。

    <!--[if !supportLists]-->7、  <!--[endif]-->元素信息:

    元素次数:无限制

    父元素:xsl:apply-templates, xsl:for-each

    子元素:无。

    <!--[if !supportLists]-->8、  <!--[endif]-->备注:

    排序算法将忽略dash(‘-‘)。

    <!--[if !supportLists]-->十五、    <!--[endif]-->xsl:element:创建一个特殊名称的输出元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:element

      name = "element-name" 

      namespace = "uri-reference"

      use-attribute-sets = QNames>

    </xsl:element>

    属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->name:

    新建输出元素的名称,是一个QName。必选

    <!--[if !supportLists]-->3、  <!--[endif]-->namespace:

    新建的输出元素的命名空间URI。如果name中的prefix(前缀)不为空,那么这个特殊的前缀将于命名空间Uri绑定在一起。

    <!--[if !supportLists]-->4、  <!--[endif]-->use-attribute-sets:

    属性集合名称,为新建输出元素设置属性集合,如果有多个属性集合名称则使用空格分开。

    <!--[if !supportLists]-->5、  <!--[endif]-->元素信息:

    元素次数:无限制

    父元素:xsl:copy, xsl:element, xsl:fallback, xsl:for-each, xsl:if, xsl:message, xsl:otherwise, xsl:param, xsl:template, xsl:variable, xsl:when, xsl:with-param, output elements

    子元素:xsl:apply-templates, xsl:attribute, xsl:call-template, xsl:choose, xsl:comment, xsl:copy, xsl:copy-of, xsl:element, xsl:for-each, xsl:if, xsl:processing-instruction, xsl:text, xsl:value-of, xsl:variable, output elements

    <!--[if !supportLists]-->十六、    <!--[endif]-->xsl:attribute-set:属性集合元素。

    <!--[if !supportLists]-->1、  <!--[endif]-->声明方式:

    <xsl:attribute-set

      name = QName

      use-attribute-sets = QNames >

    </xsl:attribute-set>

    属性说明:

    <!--[if !supportLists]-->2、  <!--[endif]-->name:

    属性集合名称,共use-attribute-sets及xsl:use-attribute-sets使用。

  • 相关阅读:
    浅谈移动前端的最佳实践(转)
    程序员的个人发展注意事项(转)
    SQL Server 维护计划实现数据库备份(Step by Step)
    每日一SQL-善用DATEADD和DATEDIFF
    Entity Framework Code First (一)Conventions
    臣服不代表解放你的手
    写在那个毕业五年的日子(转)
    测试驱动开发实践
    领域驱动设计实践上篇(转)
    WebAPI使用多个xml文件生成帮助文档(转)
  • 原文地址:https://www.cnblogs.com/zhuor/p/306516.html
Copyright © 2011-2022 走看看