Xlst样式表总结

xpath路径使用方式

一 在match中使用路径
 <xsl:template select="网上书屋/分类/书籍"/>

二 在路径中使用*号
 <xsl:template match="网上书屋/*/书籍">
 如果我们只知道网上书屋的第二层节点为书籍,而网上书屋的第一代节点无法知道,雨丝可以使用 * 来代替网上书屋的任意的第一代子节点

三 在路径中使用//
 <xsl:template select="网上书屋//书名">
 * 只能用语匹配结构树中的某一层中的任意元素,而使用//可以直接引用任意层的后代节点
 例如:<xsl:template match="/">
  <xsl:apply-template select="网上书屋//书名"/>
      </xsl:template>
  <xsl:template match="书名">
   <xsl:value-of select=".">
  </xsl:template>
 上面的例子中可以匹配结构树中所有的书名节点,当然可以把"网上书屋"去掉,直接使用//book 结果一样

四使用"@"选择元素属性
 <sl:apply-tempalate select="@类别"/>
 要从网上书屋中选择图书的分类情况可以同过"@类别"来获得书籍的分类

四 为模版选择多个元素
 xsl 允许一次选择多个节点.xsl允许使用"|"来选择模版匹配的多个元素

 <xsl:apply-template select="书名|作者|出版社"/>

 使用"|"分割的多个元素还可以是特定路径下的元素
 
 <xsl:apply-template select="书籍/书名|分类/书籍/作者|出版社"/>

五 使用"[]"为选择的元素添加条件

 如果要选择具有ISBN子元素的书籍,则
  <xsl:template match="书籍[ISBN]">
   <xsl:apply-template select="书名|作者|出版社"/>
  </xsl:template>
   
     添加多个限定条件
  <xsl:template match="书籍[ISBN|作者]">
   <xsl:apply-template select="书名|作者|出版社"/>
  </xsl:template>
  选择具有isbn,作者子元素的书籍

  在条件中使用 *
  <xsl:template match="*[ISBN]">
   <xsl:apply-template select="书名|作者|出版社"/>
  </xsl:template>
  选择具有isbn子元素的节点

 限定元素有给定属性
  <xsl:template match="书籍[@ISBN]">
   <xsl:apply-template select="书名|作者|出版社"/>
  </xsl:template>

 限定元素内容为给定字符串
  <xsl:template match="书籍[书名='c#高级编程']">
   <xsl:apply-template select="书名|作者|出版社"/>
  </xsl:template> 

<xsl:template match="w:tbl"> <xsl:variable name="colCount" select="count(w:tblGrid/w:gridCol)"/> <fo:table table-layout="fixed" width="100%" border-collapse="collapse"> <!-- 生成精确列定义 --> <xsl:for-each select="w:tblGrid/w:gridCol"> <fo:table-column column-width="{@w:w div 20}pt"/> </xsl:for-each> <fo:table-body> <!-- 列溢出检测逻辑保持不变 --> <xsl:if test="count(w:tr[1]/w:tc) > $colCount"> <fo:table-row> <fo:table-cell number-columns-spanned="{$colCount}"> <fo:block color="red">表格列数溢出警告</fo:block> </fo:table-cell> </fo:table-row> </xsl:if> <xsl:apply-templates select="w:tr"/> </fo:table-body> </fo:table> </xsl:template> <xsl:template match="w:tr"> <tr> <xsl:apply-templates select="w:tc"/> </tr> </xsl:template> <xsl:template match="w:tc"> <xsl:variable name="pos" select="count(preceding-sibling::w:tc) + 1"/> <xsl:variable name="vMergeStart" select="w:tcPr/w:vMerge/@w:val = 'restart' or (w:tcPr/w:vMerge and not(@w:val))"/> <xsl:variable name="rowspan"> <xsl:choose> <xsl:when test="$vMergeStart"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="../following-sibling::w:tr"/> <xsl:with-param name="columnPos" select="$pos"/> <xsl:with-param name="count" select="1"/> </xsl:call-template> </xsl:when> <xsl:otherwise>1</xsl:otherwise> </xsl:choose> </xsl:variable> <td> <xsl:if test="$rowspan > 1"> <xsl:attribute name="rowspan"> <xsl:value-of select="$rowspan"/> </xsl:attribute> </xsl:if> </td> </xsl:template> <xsl:template name="calculateRowspan"> <xsl:param name="currentRow"/> <xsl:param name="columnPos"/> <xsl:param name="count"/> <xsl:choose> <xsl:when test="$currentRow[1]/w:tc[position() = $columnPos]/w:tcPr/w:vMerge"> <xsl:call-template name="calculateRowspan"> <xsl:with-param name="currentRow" select="$currentRow[position() > 1]"/> <xsl:with-param name="columnPos" select="$columnPos"/> <xsl:with-param name="count" select="$count + 1"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$count"/> </xsl:otherwise> </xsl:choose> </xsl:template>我这个word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,表格处理这块不能用,设计行或者列单元格合并有问题,请修改完善,一定要注意这是word的xml转xls-fo的xlst样式表,且xsl和xml版本均为1.0,请直接给出修改结果
03-11
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值