以文本方式查看主题

-  中文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=12802)


--  作者:wsp1
--  发布时间:12/15/2004 11:01:00 PM

--  初学xsl,请帮忙看一下我的问题
目的:
       1.读取config段里的name,得到"book"和"other".
       2.分别读取book段和other段里的count值,同时把config段中book和other对应的min值读出.
       xml如下:
<?xml version="1.0" encoding="gb2312"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<types>
  <config>
    <type name="book">
      <min>2</min>
      <max>5</max>
    </type>
    <type name="other">
      <min>4</min>
      <max>8</max>
    </type>
  </config>
  <book name="a">
     <count>6</count>
  </book>
  <book name="b">
     <count>7</count>
  </book>
  <other name="c">
     <count>10</count>
  </other>
</types>
希望得到以下结果
6    2   7   2
10  4
试着写的xsl代码如下:
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/types">
  <html>
  <body>
    <Table border="1" title="test" align="center">
      <xsl:for-each select="config/type">
       <tr>
         <xsl:variable name="typename" select="@name"/>
         <xsl:for-each select="//book">
           <td><xsl:value-of select="count"/></td>
           <td><xsl:value-of select="//config/type/min"/></td>
         </xsl:for-each>
       </tr>
      </xsl:for-each>
    </Table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
此代码有两个问题:
1.<xsl:for-each select="//book">这行,怎样将book用变量typename替换调,写死的book达不到目的。
2.<td><xsl:value-of select="//config/type/min"/></td>这行,怎样读取typename代表的type在config段里的min值?
--  作者:qinxd
--  发布时间:12/16/2004 3:26:00 PM

--  
<?xml version="1.0" encoding="gb2312" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/types">
  <html>
  <body>
    <Table border="1" title="test">
      <xsl:for-each select="config/type">
         <xsl:variable name="typename" select="@name"/>
  <xsl:variable name="min" select="min"/>
       <tr>
         <xsl:for-each select="//types/child::*[contains(name(.),$typename)]">
           <td><xsl:value-of select="count"/></td>
           <td><xsl:value-of select="$min"/></td>
         </xsl:for-each>
       </tr>
      </xsl:for-each>
    </Table>
  </body>
  </html>
</xsl:template>
</xsl:stylesheet>
--  作者:wsp1
--  发布时间:12/17/2004 8:38:00 PM

--  
谢谢啦,感觉语法太复杂了

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