新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国XML论坛<<     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → 求助~关于HTML标题数字化怎样用XSLT表达? 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 7558 个阅读者浏览上一篇主题  刷新本主题   平板显示贴子 浏览下一篇主题
     * 贴子主题: 求助~关于HTML标题数字化怎样用XSLT表达? 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     98900969r 帅哥哟,离线,有人找我吗?
      
      
      威望:8
      等级:大四寒假(收到MIT的Offer啦)
      文章:235
      积分:1555
      门派:XML.ORG.CN
      注册:2005/11/2

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给98900969r发送一个短消息 把98900969r加入好友 查看98900969r的个人资料 搜索98900969r在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看98900969r的博客楼主
    发贴心情 

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xh="http://www.w3.org/1999/xhtml">
     <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

     <xsl:template match="*">
      <xsl:copy>
       <xsl:apply-templates select="@*"/>
       <xsl:apply-templates/>
      </xsl:copy>
     </xsl:template>
     
     <xsl:template match="@* | text() | processing-instruction() | comment()">
      <xsl:copy/>
     </xsl:template>
     
     <xsl:template match="text() [parent::xh:h1 or parent::xh:h2 or parent::xh:h3 or parent::xh:h4 or parent::xh:h5 or parent::xh:h6]">
      <xsl:for-each select="parent::*">
       <xsl:variable name="n0" select="number( substring-after(local-name(.), 'h') )"/>
       <xsl:variable name="n" select="$n0"/>
       <xsl:call-template name="hn">
        <xsl:with-param name="n0" select="$n0"/>
        <xsl:with-param name="n" select="$n"/>
        <xsl:with-param name="s0" select="''"/>
       </xsl:call-template>
      </xsl:for-each>
      <xsl:apply-templates/>
     </xsl:template>
     
     <xsl:template name="hn">
      <xsl:param name="n0"/>
      <xsl:param name="n"/>
      <xsl:param name="s0"/>
      <xsl:choose>
       <xsl:when test="$n>=1">
        <xsl:variable name="hp">
         <xsl:variable name="hn_1_t" select="string(preceding-sibling::* [local-name(.)=concat('h', number($n)-1)] [last()])"/>
         <xsl:choose>
          <xsl:when test="$n=1">
           <xsl:choose>
            <xsl:when test="$n!=$n0">
             <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n)])"/>
            </xsl:when>
            <xsl:otherwise>
             <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n)] )+1"/>
            </xsl:otherwise>
           </xsl:choose>
          </xsl:when>
          <xsl:otherwise>
           <xsl:choose>
            <xsl:when test="$n!=$n0">
             <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n) and preceding-sibling::* [local-name(.)=concat('h', number($n)-1) and .=$hn_1_t ] ] )"/>
            </xsl:when>
            <xsl:otherwise>
             <xsl:value-of select="count(preceding-sibling::* [local-name(.)=concat('h', $n) and preceding-sibling::* [local-name(.)=concat('h', number($n)-1) and .=$hn_1_t ] ] )+1"/>
            </xsl:otherwise>
           </xsl:choose>
          </xsl:otherwise>
         </xsl:choose>
        </xsl:variable>
        <xsl:variable name="s">
         <xsl:choose>
          <xsl:when test="$n=$n0">
           <xsl:value-of select="concat($s0, $hp, ' ', .)"/>
          </xsl:when>
          <xsl:otherwise>
           <xsl:value-of select="concat($hp, '.', $s0 )"/>
          </xsl:otherwise>
         </xsl:choose>
        </xsl:variable>
        <xsl:call-template name="hn">
         <xsl:with-param name="n0" select="$n0"/>
         <xsl:with-param name="n" select="number($n)-1"/>
         <xsl:with-param name="s0" select="$s"/>
        </xsl:call-template>
       </xsl:when>
       <xsl:otherwise>
        <xsl:value-of select="$s0"/>
       </xsl:otherwise>
      </xsl:choose>
     </xsl:template>
    </xsl:stylesheet>

    [此贴子已经被作者于2005-12-12 19:22:22编辑过]
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/12/12 14:39:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/4/28 1:10:12

    本主题贴数5,分页: [1]

     *树形目录 (最近20个回帖) 顶端 
    主题:  求助~关于HTML标题数字化怎样用XSLT表达?(504字) - glueckschwein,2005年12月10日
        回复:  感谢斑竹支持~~!!!(20字) - glueckschwein,2005年12月13日
        回复:  <?xml version="1.0" encoding="UTF-8"?><xsl:style..(3133字) - 98900969r,2005年12月12日
        回复:  呵呵, 我也认为很难~~可我不是斑竹,怎么给奖励哈~~只能顶你了~(60字) - glueckschwein,2005年12月12日
        回复:  这道题目超难,可以拿来作为比拼。得有奖励才行,呵呵。你设个奖吧,偶试试。..(72字) - 98900969r,2005年12月11日

    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    62.988ms