看XSLT,做了点笔记,比较基础、简单
基本元素、函数

1。xml文件中处理指令:
<?xml-stylesheet type="text/xsl" href="FitnessCenter.xsl"?>

2。xslt根元素
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                version="1.0">

3。输出到属性:

3.1快速用法:
无效:<Body bgcolor="<xsl:value-of select='/FitnessCenter/Member/FavoriteColor'/>">
有效:<Body bgcolor="{/FitnessCenter/Member/FavoriteColor}">

3.2 用<xsl:attribute输出属性:
<TR>
<xsl:attribute name="bgcolor">yellow</xsl:attribute>

4。一般输出:
<xsl:value-of select="/FitnessCenter/Member/Phone[@type='home']"/>

5。迭代(<xsl:for-each):
<xsl:for-each select="/FitnessCenter/Member/Phone">
       <!--用XPath取得一个XML nodeList-->
      <TR>
          <TD><xsl:value-of select="@type"/></TD>
          <TD><xsl:value-of select="."/></TD>
      </TR>
    </xsl:for-each>

   5.1 XPath用法
      <xsl:for-each select="/FitnessCenter/Member[position() != last())]">
        <!-- 除最后一个元素外都处理 -->
      </xsl:for-each>
      <xsl:for-each select="/FitnessCenter/Member[position() &gt;1]">
        <!-- 除第一个元素外都处理 -->
      </xsl:for-each>
      <xsl:for-each select="/FitnessCenter//Name">
        <!-- 取所有以FitnessCenter为辅元素的Name元素 -->
      </xsl:for-each>
   5.2叠代中的序号
      <xsl:for-each select="/FitnessCenter/Member">
        <xsl:number value="position()" format="A"/>
        <xsl:text>. </xsl:text>
        <xsl:value-of select="Name"/>
        <BR/>
      </xsl:for-each>
      其中:format(格式)可取一下值:
      format=“1” generates the sequence: 1, 2, 3, …
      format=“01” generates: 01, 02, 03, …
      format=“A” generates: A, B, C, …
      format=“a” generates: a, b, c, …
      format=“I” generates: I, II, III, …
      format=“i” generates: i, ii, iii, ...

   5.3迭代中的排序(<xsl:sort)
      <xsl:for-each select="/FitnessCenter/Member">
        <xsl:sort select="Name" order="ascending"/>
        <xsl:value-of select="Name"/>
        <BR/>
      </xsl:for-each>

6。分枝
    6.1简单:
      <xsl:for-each select="/FitnessCenter/Member[position() &gt; 1]">
                    Our special offer to platinum members today is ...
                    <BR/>
      </xsl:if>
    6.2复杂:
    <xsl:choose>
        <xsl:when test='something>
              [action]
        </xsl:when>
        <xsl:when test='something'>
              [action]
        </xsl:when>
        <xsl:otherwise>
              [action]
        </xsl:otherwise>
    </xsl:choose>
7。变量(<xsl:variable)
    7.1简单:
       <xsl:variable name="pi" select="'3.142857142857'"/>
    7.2复杂:
       <xsl:variable name="names">
         <xsl:value-of select="/FitnessCenter/Member[1]/Name"/>
         <xsl:for-each select="/FitnessCenter/Member[position() &gt; 1]">
                    <xsl:text>/</xsl:text>
                    <xsl:value-of select="Name"/>
         </xsl:for-each>
       </xsl:variable>
 



xslt例子(Coloring alternate rows和两个Template例子):
 
1。position() mode 2
例:Coloring alternate rows
<TABLE border="1" width="25%">
        <xsl:for-each select="/FitnessCenter/Member">
                  <TR>
                          <xsl:if test="position() mod 2 = 0">
                                <xsl:attribute name="bgcolor">yellow</xsl:attribute>
                          </xsl:if>
                          <TD><xsl:value-of select="Name"/></TD>
                   </TR>
         </xsl:for-each>
</TABLE>
2。Dument(url) :指向外部另一个Xml文档
<xsl:variable name="fitnessCenter2"
                select="document('file://localhost/xml-course/.../FitnessCenter2.xml')"/>
        <xsl:for-each select="$fitnessCenter2/FitnessCenter/Member">
3。<xsl:call-template
例:使用带参数(param)的模板(template)
<xsl:template match="/">
        <HTML>
            <HEAD>
                <TITLE>Fitness Center</TITLE>
            </HEAD>
            <BODY>
                <xsl:call-template name="displayNameWithFont">
                    <xsl:with-param name="fontFace" select="'Impact'"/>
                    <xsl:with-param name="name"
                            select="/FitnessCenter/Member[1]/Name"/>
                </xsl:call-template>
                <BR/>
                ...
            </BODY>
        </HTML>
    </xsl:template>
    <xsl:template name="displayNameWithFont">
        <xsl:param name="fontFace" select="'Braggadocio'"/> <!-- default font -->
        <xsl:param name="name"/>
        <FONT face="{$fontFace}">
            <xsl:value-of select="$name"/>
        </FONT>
    </xsl:template>
使用带参数的模板例二:
<xsl:template match="/">
        <HTML>
            <HEAD>
                <TITLE>Fitness Center</TITLE>
            </HEAD>
            <BODY>
                16 / 2 =
                <xsl:variable name="result">
                    <xsl:call-template name="NumDiv2">
                         <xsl:with-param name="N" select="16"/>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:value-of select="$result"/>
            </BODY>
        </HTML>
    </xsl:template>
    <xsl:template name="NumDiv2">
        <xsl:param name="N"/>
        <xsl:value-of select="$N div 2"/>
    </xsl:template>