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

    >> 本版讨论XSL,XSLT,XSL-FO,CSS等技术
    [返回] W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWLXML.ORG.CN讨论区 - XML技术『 XSL/XSLT/XSL-FO/CSS 』 → 紧急救助xslt和xpath处理两个xml文档的问题,救命啊 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 15749 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: 紧急救助xslt和xpath处理两个xml文档的问题,救命啊 举报  打印  推荐  IE收藏夹 
       本主题类别: 样式表技术(XSL, XSLT, XSL-FO, CSS) | XML文档存取技术(DOM, SAX)    
     abc911 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:57
      门派:XML.ORG.CN
      注册:2010/5/27

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给abc911发送一个短消息 把abc911加入好友 查看abc911的个人资料 搜索abc911在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看abc911的博客楼主
    发贴心情 紧急救助xslt和xpath处理两个xml文档的问题,救命啊

    用xslt和xpath处理fc.xml和footyresult.xml, 要求:
    在fc.xml里面找出各个<team>里面的<name>和<headCoach>然后在footyresult.xml里面的/season/round路径下找出 math里面的team的name对应fc.xml里面的team name. 输出:team的分数score里的<goal>和<behind>

    文件如下:
    [color=#FF0000]fc.xml:[/color]

    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="q4b.xsl"?>
    <footballClub xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FC.xsd">
     <team>
      <name>Brisbane Lions</name>
      <address>Brisbane</address>
      <captain>S.Black</captain>
      <headCoach>L.Matthews</headCoach>
     </team>
     <team>
      <name>Carlton Blues</name>
      <address>Carlton</address>
      <captain>N.Stevens</captain>
      <headCoach>D.Pagan</headCoach>
     </team>
     <team>
      <name>Collingwood Magpies</name>
      <address>Collingwood</address>
      <captain>N.Buckley</captain>
      <headCoach>M.Malthouse</headCoach>
     </team>
     <team>
      <name>Essendon Bombers</name>
      <address>Essendon</address>
      <captain>M.Loyd</captain>
      <headCoach>K.Sheedy</headCoach>
     </team>
     <team>
      <name>Fremantle Dockers</name>
      <address>Fremantle</address>
      <captain>M.Pavlich</captain>
      <headCoach>C.Connolly</headCoach>
     </team>
     <team>
      <name>Geelong Cats</name>
      <address>Geelong</address>
      <captain>T.Harley</captain>
      <headCoach>M.Thompson</headCoach>
     </team>
     <team>
      <name>Hawthorn Hawks</name>
      <address>Hawthorn</address>
      <captain>S.Mitchell</captain>
      <headCoach>A.Clarkson</headCoach>
     </team>
     <team>
      <name>Melbourne Demons</name>
      <address>Melbourne</address>
      <captain>D.Neitz</captain>
      <headCoach>N.Danniher</headCoach>
     </team>
     <team>
      <name>North Melbourne Kangaroos</name>
      <address>North Melbourne</address>
      <captain>A.Simpson</captain>
      <headCoach>D.Laidley</headCoach>
     </team>
     <team>
      <name>Port Adelaide Powers</name>
      <address>Port Adelaide</address>
      <captain>W.Treadrea</captain>
      <headCoach>M.Williams</headCoach>
     </team>
     <team>
      <name>Richmond Tigers</name>
      <address>Richmond</address>
      <captain>K.Jonhson</captain>
      <headCoach>T.Wallace</headCoach>
     </team>
     <team>
      <name>Saint Kilda Saints</name>
      <address>Saint Kilda</address>
      <captain>N.Riewoldt</captain>
      <captain>L.Ball</captain>
      <headCoach>G.Thomas</headCoach>
     </team>
     <team>
      <name>Sydney Swans</name>
      <address>Sydney</address>
      <captain>B.Kirk</captain>
      <captain>L.Barry</captain>
      <captain>B.Hall</captain>
      <headCoach>P.Roos</headCoach>
     </team>
     <team>
      <name>West Coast Eagles</name>
      <address>Perth</address>
      <captain>C.Judd</captain>
      <headCoach>J.Worsfold</headCoach>
     </team>
     <team>
      <name>Western Bulldogs</name>
      <address>Footscray</address>
      <captain>B.Johnson</captain>
      <headCoach>R.Eade</headCoach>
     </team>
     <team>
      <name>Adelaide Crows</name>
      <address>Adelaide</address>
      <captain>S.Goodwin</captain>
      <headCoach>N.Craig</headCoach>
     </team>
    </footballClub>

    [/QUOTE]

    [color=#FF0000]footyresult.xml:[/color]
    [QUOTE]
    <?xml version="1.0"?>
    <?xml-stylesheet type="text/xsl" href="q2a.xsl"?>
    <season year="2007" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="footyResults.xsd">
     <round no="1">
      <match gameNo="1">
       <team home="yes">
        <name>Melbourne Demons</name>
        <score>
         <goal>9</goal>
         <behind>8</behind>
        </score>
        <highestGoalKicker>
         <name>D.Neitz</name>
         <goal>3</goal>
        </highestGoalKicker>
        <highestGoalKicker>
         <name>R.Robertson</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Saint Kilda Saints</name>
        <score>
         <goal>13</goal>
         <behind>15</behind>
        </score>
        <highestGoalKicker>
         <name>F.?Gehrig</name>
         <goal>4</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="2">
       <team home="yes">
        <name>Fremantle Dockers</name>
        <score>
         <goal>16</goal>
         <behind>0</behind>
        </score>
        <highestGoalKicker>
         <name>M.Pavlich</name>
         <goal>5</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Port Adelaide Powers</name>
        <score>
         <goal>19</goal>
         <behind>7</behind>
        </score>
        <highestGoalKicker>
         <name>D.White</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="3">
       <team home="no">
        <name>Collingwood Magpies</name>
        <score>
         <goal>12</goal>
         <behind>10</behind>
        </score>
        <highestGoalKicker>
         <name>P.Medhurst</name>
         <goal>2</goal>
        </highestGoalKicker>
       </team>
       <team home="yes">
        <name>North Melbourne Kangaroos</name>
        <score>
         <goal>10</goal>
         <behind>19</behind>
        </score>
        <highestGoalKicker>
         <name>B.Harvey</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="4">
       <team home="yes">
        <name>Brisbane Lions</name>
        <score>
         <goal>9</goal>
         <behind>15</behind>
        </score>
        <highestGoalKicker>
         <name>A.McGrath</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Hawthorn Hawks</name>
        <score>
         <goal>6</goal>
         <behind>8</behind>
        </score>
        <highestGoalKicker>
         <name>L.Franklin</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="5">
       <team home="yes">
        <name>Sydney Swans</name>
        <score>
         <goal>10</goal>
         <behind>13</behind>
        </score>
        <highestGoalKicker>
         <name>N.Davis</name>
         <goal>2</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>West Coast Eagles</name>
        <score>
         <goal>11</goal>
         <behind>8</behind>
        </score>
        <highestGoalKicker>
         <name>M.Seaby</name>
         <goal>2</goal>
        </highestGoalKicker>
        <highestGoalKicker>
         <name>C.Judd</name>
         <goal>2</goal>
        </highestGoalKicker>
        <highestGoalKicker>
         <name>A.Hunter</name>
         <goal>2</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="6">
       <team home="yes">
        <name>Adelaide Crows</name>
        <score>
         <goal>10</goal>
         <behind>14</behind>
        </score>
        <highestGoalKicker>
         <name>N.Bock</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Essendon Bombers</name>
        <score>
         <goal>16</goal>
         <behind>9</behind>
        </score>
        <highestGoalKicker>
         <name>S.Lucas</name>
         <goal>7</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="7">
       <team home="yes">
        <name>Western Bulldogs</name>
        <score>
         <goal>17</goal>
         <behind>11</behind>
        </score>
        <highestGoalKicker>
         <name>B.Johnson</name>
         <goal>8</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Geelong Cats</name>
        <score>
         <goal>13</goal>
         <behind>15</behind>
        </score>
        <highestGoalKicker>
         <name>C.Mooney</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
      </match>
      <match gameNo="8">
       <team home="yes">
        <name>Carlton Blues</name>
        <score>
         <goal>15</goal>
         <behind>25</behind>
        </score>
        <highestGoalKicker>
         <name>B.Fevola</name>
         <goal>3</goal>
        </highestGoalKicker>
       </team>
       <team home="no">
        <name>Richmond Tigers</name>
        <score>
         <goal>15</goal>
         <behind>8</behind>
        </score>
        <highestGoalKicker>
         <name>K.Pettifer</name>
         <goal>4</goal>
        </highestGoalKicker>
       </team>
      </match>
     </round>
    </season>



       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/5/27 16:20:00
     
     jj_long 帅哥哟,离线,有人找我吗?
      
      
      威望:1
      等级:大三(面向对象是个好东东!)
      文章:42
      积分:574
      门派:XML.ORG.CN
      注册:2008/7/29

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jj_long发送一个短消息 把jj_long加入好友 查看jj_long的个人资料 搜索jj_long在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jj_long的博客2
    发贴心情 
    看一下能否解决你的问题:

    XSLT:
    ============================================
    <?xml version='1.0'?>

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html" indent="yes"/>


    <xsl:variable name="v_footyresult" select="document('footyresult.xml')"></xsl:variable>

    <xsl:template match="/">
     <html>
      <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
      <title>Score</title>
      <style type="text/css">
       body{
        font-family:Arial, Helvetica, sans-serif;
        font-size:9px;
       }
       table{
        font-family:Arial, Helvetica, sans-serif;
        font-size:99x;
       }
      </style>
      </head>
      <body>
       <table border="1" width="90%" align="center">
        <caption>Score</caption>
        <tr>
         <th>name</th>
         <th>headCoach</th>
         <th>goal</th>
         <th>behind</th>
        </tr>
        <xsl:apply-templates/>
       </table>
      </body>
     </html>
    </xsl:template>

    <xsl:template match="team">
     <xsl:variable name="v_name" select="name"/>
     <tr>
      <td><xsl:value-of select="$v_name"/></td>
      <td><xsl:value-of select="headCoach"/></td>
      <td><xsl:value-of select="$v_footyresult/season/round/match/team[name=$v_name]/score/goal"/></td>
      <td><xsl:value-of select="$v_footyresult/season/round/match/team[name=$v_name]/score/behind"/></td>
     </tr>
    </xsl:template>


    </xsl:stylesheet>
    =============================================

    输出结果:
    =============================================
    <html>
       <head>
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
       
          <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
          <title>Score</title><style type="text/css">
       body{
        font-family:Arial, Helvetica, sans-serif;
        font-size:9px;
       }
       table{
        font-family:Arial, Helvetica, sans-serif;
        font-size:99x;
       }
      </style></head>
       <body>
          <table border="1" width="90%" align="center">
             <caption>Score</caption>
             <tr>
                <th>name</th>
                <th>headCoach</th>
                <th>goal</th>
                <th>behind</th>
             </tr>
             
             <tr>
                <td>Brisbane Lions</td>
                <td>L.Matthews</td>
                <td>9</td>
                <td>15</td>
             </tr>
              
             <tr>
                <td>Carlton Blues</td>
                <td>D.Pagan</td>
                <td>15</td>
                <td>25</td>
             </tr>
              
             <tr>
                <td>Collingwood Magpies</td>
                <td>M.Malthouse</td>
                <td>12</td>
                <td>10</td>
             </tr>
              
             <tr>
                <td>Essendon Bombers</td>
                <td>K.Sheedy</td>
                <td>16</td>
                <td>9</td>
             </tr>
              
             <tr>
                <td>Fremantle Dockers</td>
                <td>C.Connolly</td>
                <td>16</td>
                <td>0</td>
             </tr>
              
             <tr>
                <td>Geelong Cats</td>
                <td>M.Thompson</td>
                <td>13</td>
                <td>15</td>
             </tr>
              
             <tr>
                <td>Hawthorn Hawks</td>
                <td>A.Clarkson</td>
                <td>6</td>
                <td>8</td>
             </tr>
              
             <tr>
                <td>Melbourne Demons</td>
                <td>N.Danniher</td>
                <td>9</td>
                <td>8</td>
             </tr>
              
             <tr>
                <td>North Melbourne Kangaroos</td>
                <td>D.Laidley</td>
                <td>10</td>
                <td>19</td>
             </tr>
              
             <tr>
                <td>Port Adelaide Powers</td>
                <td>M.Williams</td>
                <td>19</td>
                <td>7</td>
             </tr>
              
             <tr>
                <td>Richmond Tigers</td>
                <td>T.Wallace</td>
                <td>15</td>
                <td>8</td>
             </tr>
              
             <tr>
                <td>Saint Kilda Saints</td>
                <td>G.Thomas</td>
                <td>13</td>
                <td>15</td>
             </tr>
              
             <tr>
                <td>Sydney Swans</td>
                <td>P.Roos</td>
                <td>10</td>
                <td>13</td>
             </tr>
              
             <tr>
                <td>West Coast Eagles</td>
                <td>J.Worsfold</td>
                <td>11</td>
                <td>8</td>
             </tr>
              
             <tr>
                <td>Western Bulldogs</td>
                <td>R.Eade</td>
                <td>17</td>
                <td>11</td>
             </tr>
              
             <tr>
                <td>Adelaide Crows</td>
                <td>N.Craig</td>
                <td>10</td>
                <td>14</td>
             </tr>
             
          </table>
       </body>
    </html>
    =============================================

    注:我使用了Saxon 6.5.5调试此程序。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/5/27 23:59:00
     
     abc911 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:2
      积分:57
      门派:XML.ORG.CN
      注册:2010/5/27

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给abc911发送一个短消息 把abc911加入好友 查看abc911的个人资料 搜索abc911在『 XSL/XSLT/XSL-FO/CSS 』的所有贴子 引用回复这个贴子 回复这个贴子 查看abc911的博客3
    发贴心情 
    非常感谢
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2010/5/28 6:19: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/11/26 0:56:04

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

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