以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  一个XSL的问题, 谢谢各位了  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=31460)


--  作者:thomascheung
--  发布时间:4/28/2006 11:30:00 AM

--  一个XSL的问题, 谢谢各位了
这是XML:

<?xml version="1.0" encoding="ISO-8859-1"?>


 <records name="offerlist">
  <record>
   <country>HK</country>
   <name>hk offer1</name>
  </record>
  <record>
   <country>HK</country>
   <name>hk offer2</name>
  </record>
  <record>
   <country>HK</country>
   <name>hk offer3</name>
  </record>
  <record>
   <country>HK</country>
   <name>hk offer4</name>
  </record>
  <record>
   <country>SG</country>
   <name>sg offer1</name>
  </record>
  <record>
   <country>SG</country>
   <name>sg offer2</name>
  </record>
  <record>
   <country>SG</country>
   <name>sg offer3</name>
  </record>
  <record>
   <country>TW</country>
   <name>tw offer1</name>
  </record>
  <record>
   <country>TW</country>
   <name>tw offer2</name>
  </record>
  <record>
   <country>TW</country>
   <name>tw offer3</name>
  </record>
 </records>
 
 <records name="countrylist">
  <record>
   <country>HK</country>
   <name>Hong Kong</name>
  </record>
  <record>
   <country>CN</country>
   <name>China</name>
  </record>
  <record>
   <country>SG</country>
   <name>Singapor</name>
  </record>
 </records>

这是XSL:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">
  <html>
  <body>
    <h2>Country Offer</h2>
    <table border="1">
      <xsl:for-each select="records[@name='offerlist']/record">
       <xsl:call-template name="displayCountry" />      
       <xsl:call-template name="displayName" />      
      </xsl:for-each>
  </table>
  </body>
  </html>
</xsl:template>


<xsl:template name="displayCountry">    
 <xsl:variable name="currentCountry">
      <xsl:value-of select="country"/>
 </xsl:variable>           
 <xsl:variable name="prevpos" select="position()-1"/>
 <xsl:variable name="previousCountry">    
     <xsl:choose>
         <xsl:when test="$prevpos &gt; 0">
              <xsl:value-of select="../record[$prevpos]/country"/>              
         </xsl:when>
  <xsl:otherwise>
     <xsl:value-of select="''"/>
  </xsl:otherwise>
     </xsl:choose>             
 </xsl:variable>            
 <xsl:if test="$currentCountry != $previousCountry"> 
  <tr><td><b>Country: <xsl:value-of select="$currentCountry"/></b></td></tr>
 </xsl:if>
</xsl:template>

<xsl:template name="displayName">   
 <xsl:for-each select="name">
      <tr><td><xsl:value-of select="."/></td></tr>
     </xsl:for-each>
</xsl:template>

</xsl:stylesheet>

我想在XSL原有的基础上做些改动, 使得"offerlist"里面的"country"可以跟"countrylist"里面的"country"做比较, 然后把"countrylist"里面的"country"显示出来


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