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

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] 中文XML论坛 - 专业的XML技术讨论区XML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → [原创]我的一个xslt,请大家分享,不要吐我 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 2272 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [原创]我的一个xslt,请大家分享,不要吐我 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     bjshengyu333 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:8
      积分:105
      门派:XML.ORG.CN
      注册:2005/8/11

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给bjshengyu333发送一个短消息 把bjshengyu333加入好友 查看bjshengyu333的个人资料 搜索bjshengyu333在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看bjshengyu333的博客楼主
    发贴心情 [原创]我的一个xslt,请大家分享,不要吐我

    <?xml version="1.0" encoding="GB2312"?>
    <xsl:stylesheet xmlns:cps="xalan://com.emy.cps.misc.CpsUtils" xmlns:java="http://xml.apache.org/xslt/java" xmlns:token="xalan://java.util.StringTokenizer" xmlns:vars="xalan://java.util.HashMap" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" exclude-result-prefixes="java vars cps token" version="1.0">
        <xsl:output encoding="UTF-8" method="xml"/>
        <xsl:template match="html">
            <xsl:choose>
                <xsl:when test="$page_mode='check'">
                    <xsl:apply-templates mode="check" select="/"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates mode="normal" select="/"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
        <!--
           imput parameters:
         description:
         page_mode    
           page_url   
           page_category  
           page_url   
         page_<param>   其他参数,由上级页面传递过来,如果                                                           需要使用,则需要加上相关定义。
          例如,如果要传递title, 则需要加入:

        -->
        <xsl:param name="page_mode">normal</xsl:param>
        <xsl:param name="page_sid">cps</xsl:param>
        <xsl:param name="page_schema">news</xsl:param>
        <xsl:param name="page_supplier">CPS_SYSTEM</xsl:param>
        <xsl:param name="page_category">/CPS_SYSTEM</xsl:param>
        <xsl:param name="page_refpage">http://www/</xsl:param>
        <xsl:param name="page_url">http://www/</xsl:param>

        <xsl:param name="page_style_channel_name_pattern"/>
        <xsl:param name="page_style_channel_url_pattern"/>
        
        <xsl:param name="page_style_channel_subcategory_url_pattern"/>
        <xsl:param name="page_style_channel_nonsubcategory_url_pattern"/>
        <xsl:param name="page_style_channel_subcategory_name_modifier"/>
        <xsl:param name="page_style_title_url_pattern"/>
        <xsl:param name="page_style_title_modifier"/>
        <xsl:param name="page_style_title_allow_keywords"/>
        <xsl:param name="page_style_title_deny_keywords"/>


    <!-- 最新加上的参数,正在测试阶段 -->
        <xsl:param name="page_style_channel_level" select="'token'"/>
        <xsl:param name="page_style_define_channel_self" select="'首页新闻'"/>
        <xsl:param name="page_style_subcategory_name_pattern"/>
        <xsl:param name="page_style_subcategory_url_pattern"/>

        <xsl:param name="page_style_channel_name_token"/>
        <xsl:param name="page_style_channel_url_token"/>
        <xsl:param name="page_style_base_url_top"/>
        <xsl:param name="page_style_base_url_foot"/>

      <xsl:param name="page_style_max_title_page_no" select="4"/>
        <xsl:param name="page_title_currently_page_no" select="1"/>
        <xsl:param name="page_style_title_next_page_url_pattern" select="'[p|P]age=(\d+)'"/>
        <!--
            STD MOD: <xsl:template match="html" mode="normal">
        -->
    <!-- 这里选择页面的级数 -->
    <xsl:template match="html" mode="normal">
       <webinfo>
       <xsl:if test="vars:put('_page_style_channel_level','')"/>
       <xsl:choose>
       <xsl:when test="$page_style_channel_level='token'">
             <xsl:if test="vars:put('_page_style_channel_level','subcategory')"/>
             <xsl:call-template name="define-category"/>
          </xsl:when>
     <xsl:when test="$page_style_channel_level='main'">
           <xsl:apply-templates mode="a-main" select="body"/>
     </xsl:when>
     <xsl:when test="$page_style_channel_level='subcategory'">
           <xsl:apply-templates mode="a-subcategory" select="body"/>
       </xsl:when>
     <xsl:otherwise>
     <!-- nothing -->
     </xsl:otherwise>
    </xsl:choose>
    <!--  判断是否取下一页 -->
          <xsl:choose>
           <xsl:when test="string-length($page_style_max_title_page_no)&lt;1">
                <xsl:apply-templates mode="next-page" select="body"/> 
           </xsl:when>
           <xsl:otherwise>
             <xsl:if test="not(number($page_style_max_title_page_no)&lt;number($page_title_currently_page_no)) and $page_style_title_next_page_url_pattern!=''">
                   <xsl:apply-templates mode="next-page" select="body"/>
               </xsl:if>
           </xsl:otherwise>
          </xsl:choose>
         </webinfo>
    </xsl:template>

    <!-- 得到下一页,注意这里要把主帖id和页号传入参数,其他主帖的相关信息也应传入 -->
    <xsl:template match="body" mode="next-page">
    <!--   屏幕输出页数  -->
        <xsl:variable name="out" select="java:com.emy.cps.ClientTools.getLog('currently_page:::title ')"/>
        <xsl:variable name="useless" select="java:error($out, concat('=============',$page_title_currently_page_no))"/>
        <xsl:if test="vars:put('_keep_onlyone_pass','true')"/>
        <xsl:variable name="estimate_next_page_no" select="number($page_title_currently_page_no)+1"/>       
        <xsl:for-each select=".//a[@href]">
           <xsl:variable name="url" select="cps:concatUrl($page_url,string(@href))"/>
          <xsl:if test="cps:isMatchPattern($url,$page_style_title_next_page_url_pattern)">
              <xsl:variable name="keep_onlyone_pass" select="vars:get('_keep_onlyone_pass')"/>
       <xsl:variable name="next_page_no" select="cps:getPattern($url,$page_style_title_next_page_url_pattern,1)"/>
           <xsl:if test="$next_page_no=$estimate_next_page_no and $keep_onlyone_pass='true'">
              <xsl:if test="vars:put('_keep_onlyone_pass','false')"/>
       <infocategory>
        <xsl:attribute name="supplier">
                     <xsl:value-of select="$page_supplier"/>
                  </xsl:attribute>
        <xsl:attribute name="category">
                     <xsl:value-of select="$page_category"/>
                  </xsl:attribute>
        <xsl:attribute name="url">
                     <xsl:value-of select="$url"/>
                  </xsl:attribute>
        <xsl:attribute name="title_currently_page_no">
                     <xsl:value-of select="number($next_page_no)"/>
                  </xsl:attribute>
      </infocategory>
      </xsl:if>
     </xsl:if>
      </xsl:for-each>
    </xsl:template>

    <!-- 处理首页面 -->
    <xsl:template match="body" mode="a-main">
      <xsl:if test="vars:put('_main_position','false')"/>
      <xsl:if test="$page_style_channel_url_pattern!='' or  $page_style_channel_name_pattern!=''">
      <xsl:for-each select=".//a[@href]">
        <xsl:variable name="url" select="cps:concatUrl($page_url, string(@href))"/>
        <xsl:variable name="text" select="normalize-space(.)"/>
         <xsl:if test="$url!='' and cps:isMatchPattern($url,$page_style_channel_url_pattern) and cps:isMatchPattern($text,$page_style_channel_name_pattern)">
          <xsl:if test="vars:put('_main_position','true')"/>
    <!--  -->
          <xsl:variable name="category">
            <xsl:choose>
              <xsl:when test="cps:isMatchPattern($url, $page_style_channel_subcategory_url_pattern)">
               <xsl:choose>
                 <xsl:when test="$page_style_channel_subcategory_name_modifier!=''">
                  <xsl:variable name="modified_text" select="cps:getPattern($text, $page_style_channel_subcategory_name_modifier, 1)"/>
                   <xsl:value-of select="concat($page_category, '/', $modified_text)"/>
                </xsl:when>
             <xsl:otherwise>
             <xsl:value-of select="concat($page_category, '/', $text)"/>
             </xsl:otherwise>
           </xsl:choose>
         </xsl:when>
         <xsl:when test="$page_style_channel_nonsubcategory_url_pattern!='' and cps:isMatchPattern($url, $page_style_channel_nonsubcategory_url_pattern)">
          <xsl:value-of select="$page_category"/>
           </xsl:when>
          <xsl:otherwise>
             <xsl:value-of select="$page_category"/>
         </xsl:otherwise>
       </xsl:choose>
      </xsl:variable>
      <xsl:if test="vars:put('_page_style_channel_level','subcategory')"/>
        <xsl:apply-templates mode="a-info-category" select=".">
             <xsl:with-param name="url" select="$url"/>
             <xsl:with-param name="category" select="$category"/>
          </xsl:apply-templates>
         </xsl:if>
       </xsl:for-each>
       </xsl:if>
    <!--  没有匹配的情况 -->
      <xsl:if test="vars:get('_main_position')='false'">
        <xsl:for-each select=".//a">
           <xsl:variable name="url" select="cps:concatUrl($page_url, string(@href))"/>
             <xsl:if test="cps:isMatchPattern($url, $page_style_title_url_pattern)">
              <xsl:apply-templates mode="a-news-title-with-filter" select=".">
                   <xsl:with-param name="category">
                        <xsl:choose>
                       <xsl:when test="$page_style_define_channel_self!=''">
                        <xsl:value-of select="concat($page_category,'/',$page_style_define_channel_self)"/>
                         </xsl:when>
                        <xsl:otherwise>
                             <xsl:value-of select="$page_category"/>
                         </xsl:otherwise>
                         </xsl:choose>
                      </xsl:with-param>
              </xsl:apply-templates>
             </xsl:if>
    </xsl:for-each>
       </xsl:if>
    </xsl:template>


    <!-- 处理子页面 -->
    <xsl:template match="body" mode="a-subcategory">
       <xsl:if test="vars:put('_position','false')"/>
       <xsl:if test="$page_style_subcategory_url_pattern!='' or  $page_style_subcategory_name_pattern!=''">
       <xsl:for-each select=".//a[@href]">
         <xsl:variable name="url" select="cps:concatUrl($page_url, string(@href))"/>
         <xsl:variable name="text" select="normalize-space(.)"/>
         <xsl:if test="$url!='' and cps:isMatchPattern($url,$page_style_subcategory_url_pattern) and cps:isMatchPattern($text,$page_style_subcategory_name_pattern)">
          <!--xsl:variable name="position" select="position()"/-->
          <xsl:if test="vars:put('_position','true')"/>
          <xsl:variable name="category" select="concat($page_category,'/',$text)"/>
          <xsl:if test="vars:put('_page_style_channel_level','subcategory')"/>
          <xsl:apply-templates mode="a-info-category" select=".">
             <xsl:with-param name="url" select="$url"/>
             <xsl:with-param name="category" select="$category"/>
           </xsl:apply-templates>
        </xsl:if>
      </xsl:for-each>
      </xsl:if>
    <!-- 没有匹配的情况  -->
       <xsl:if test="vars:get('_position')='false'">
         <xsl:for-each select=".//a">
                     <xsl:variable name="url" select="cps:concatUrl($page_url, string(@href))"/>
              <xsl:if test="cps:isMatchPattern($url, $page_style_title_url_pattern)">
              <xsl:apply-templates mode="a-news-title-with-filter" select=".">
                  <xsl:with-param name="category" select="$page_category"/>
              </xsl:apply-templates>
             </xsl:if>
          </xsl:for-each>
      </xsl:if>
    </xsl:template>

        <!--
            STD MOD:  result::a-info-category
             
         -->
    <xsl:template match="a" mode="a-info-category">
            <xsl:param name="category"/>
            <xsl:param name="url"/>
            <infocategory>
                <xsl:attribute name="supplier">
                    <xsl:value-of select="$page_supplier"/>
                </xsl:attribute>
                <xsl:attribute name="category">
                    <xsl:value-of select="$category"/>
                </xsl:attribute>
                <xsl:attribute name="url">
                    <xsl:value-of select="$url"/>
                </xsl:attribute>
                <xsl:attribute name="style_channel_level">
                    <xsl:value-of select="vars:get('_page_style_channel_level')"/>
                </xsl:attribute>
            </infocategory>
        </xsl:template>


    <!--
         STD MOD:  result::define-category
             

    -->
    <xsl:template name="define-category">
        <xsl:variable name="name_token" select="token:new(string($page_style_channel_name_token),'|')"/>
        <xsl:variable name="url_token" select="token:new($page_style_channel_url_token,'|')"/>
         <xsl:variable name="token_count" select="number(token:countTokens($name_token))"/>
         <xsl:for-each select="cps:makeNodeLoop($token_count)/*">
             <xsl:variable name="temp_name" select="token:nextToken($name_token)"/>
             <xsl:variable name="temp_url" select="token:nextToken($url_token)"/>
             <xsl:variable name="category" select="$temp_name"/>
             <xsl:variable name="url" select="concat($page_style_base_url_top,$temp_url,$page_style_base_url_foot)"/>
              <infocategory>
                <xsl:attribute name="supplier">
                    <xsl:value-of select="$page_supplier"/>
                </xsl:attribute>
                <xsl:attribute name="category">
                    <xsl:value-of select="concat($page_category,'/',$category)"/>
                </xsl:attribute>
                <xsl:attribute name="url">
                    <xsl:value-of select="$url"/>
                </xsl:attribute>
                <xsl:attribute name="style_channel_level">
                    <xsl:value-of select="vars:get('_page_style_channel_level')"/>
                </xsl:attribute>
            </infocategory>
        </xsl:for-each>

    <!--
           
    -->
        </xsl:template>


        <!--
            STD MOD; result::a-news-title-with-filter
            1.对标题进行修改,参数:page_style_title_modifier
                    2.其他参数:           page_style_title_allow_keywords
                                                                page_style_title_deny_keywords
        -->
        <xsl:template match="a" mode="a-news-title-with-filter">
         <xsl:param name="category"/>
            <xsl:variable name="text" select="normalize-space(.)"/>
            <xsl:variable name="text" select="cps:removePattern($text,'null\s*')"/>
            <xsl:variable name="title">
                <xsl:choose>
                    <xsl:when test="$page_style_title_modifier!='' and cps:isMatchPattern($text,$page_style_title_modifier)">
                        <xsl:value-of select="cps:getPattern($text, $page_style_title_modifier, 1)"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$text"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <xsl:variable name="url" select="cps:concatUrl($page_url, @href)"/>
            <xsl:if test="$title!='null' and string-length($title)&gt;=2">
                <xsl:choose>
                    <xsl:when test="$page_style_title_allow_keywords!=''">
                        <xsl:choose>
                            <xsl:when test="cps:isMatchPattern($title, $page_style_title_allow_keywords)">
                                <infocategory _type="news">
                                    <xsl:attribute name="_schema">
                                        <xsl:value-of select="$page_schema"/>
                                    </xsl:attribute>
                                    <xsl:attribute name="supplier">
                                        <xsl:value-of select="$page_supplier"/>
                                    </xsl:attribute>
                                    <xsl:attribute name="category">
                                        <xsl:value-of select="$category"/>
                                    </xsl:attribute>
                                    <xsl:attribute name="title">
                                        <xsl:value-of select="$title"/>
                                    </xsl:attribute>
                                    <xsl:attribute name="url">
                                        <xsl:value-of select="$url"/>
                                    </xsl:attribute>
                                </infocategory>
                            </xsl:when>
                        </xsl:choose>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:if test="$page_style_title_deny_keywords='' or not(cps:isMatchPattern($title, $page_style_title_deny_keywords))">
                            <infocategory _type="news">
                                <xsl:attribute name="_schema">
                                    <xsl:value-of select="$page_schema"/>
                                </xsl:attribute>
                                <xsl:attribute name="supplier">
                                    <xsl:value-of select="$page_supplier"/>
                                </xsl:attribute>
                                <xsl:attribute name="category">
                                    <xsl:value-of select="$category"/>
                                </xsl:attribute>
                                <xsl:attribute name="title">
                                    <xsl:value-of select="$title"/>
                                </xsl:attribute>
                                <xsl:attribute name="url">
                                    <xsl:value-of select="$url"/>
                                </xsl:attribute>
                            </infocategory>
                        </xsl:if>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:if>
        </xsl:template>
    </xsl:stylesheet>


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/8/11 14:59:00
     
     孤独 帅哥哟,离线,有人找我吗?
      
      
      威望:7
      等级:大三(面向对象是个好东东!)(版主)
      文章:826
      积分:4220
      门派:XML.ORG.CN
      注册:2004/1/14

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给孤独发送一个短消息 把孤独加入好友 查看孤独的个人资料 搜索孤独在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看孤独的博客2
    发贴心情 
    必须以来java类库哦...
    支持一个.

    ----------------------------------------------
    <?xml version="1.0" encoding="gb2312"?>
    <个人签名>
      <Website>[url=http://www.mahaobo.cn]
    MaHaobo.cn[/url]
    </Website>
    <Email>aloning(at)gmail.com</Email>
      <Qq >32113739</Qq>
    </个人签名>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/8/11 20:50: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/5/14 10:04:06

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

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    125.000ms