以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  怎么样取子节点的属性值进行递归操作(急*急*急*急*急*)  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=77954)


--  作者:hxs8731
--  发布时间:10/26/2009 2:49:00 PM

--  怎么样取子节点的属性值进行递归操作(急*急*急*急*急*)
我的xml文件是这样的:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="+FACTOR.xsl"?>
<factor>
    <check>
        <ruler type="OS" cmp="ge" value="3.0.0">
            <ruler type="OS" cmp="lt" value="4.0.0">
                <ruler type="aS" cmp="lt" value="2.0.0">
                    <ruler type="dS" cmp="lt" value="5.0.0"/>
                </ruler>
            </ruler>   
        </ruler>
    </check>
    <check>
        <ruler type="screen" cmp="ge" value="240x320"/>
    </check>
    <check>
        <ruler type="mobius" cmp="ge" value="3.0.0">
            <ruler type="mobius" cmp="lt" value="4.0.0"/>
        </ruler>
    </check>
    <check>
        <ruler type="memory" cmp="ge" value="750k"/>
    </check>
</factor>
我要分别罗列每一条check下的ruler属性值;
<xsl:for-each select="//ruler/@*">
<xsl:value-of select="."/>
</xsl:for-each>
这样能罗列出所有的属性,但没有实现我要的效果.

哪位达人来帮我解决一下!我已经困扰3天 了! 非常感谢!


--  作者:hxs8731
--  发布时间:10/27/2009 2:06:00 PM

--  
解决了! 昨天研究了一天终于把那问题解决了。
贴一下我解决的代码,以下代码文件是+factor.xsl;
<code>=======================
============================

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


<xsl:template match="/">
  <html>
  <style type="text/css">
  *{margin:0;padding:2px;}
  </style>
  <body>
    <h1>依赖关系</h1>
  <br />
  <xsl:apply-templates select="factor" />
  </body>
  </html>
</xsl:template>


<xsl:template match="factor">
<xsl:for-each select="check">
<h2><xsl:value-of select="local-name()"/></h2>
<xsl:for-each select="ruler">
 <div style="width:100%;">
  <h4><xsl:value-of select="local-name()"/></h4> 
  <xsl:call-template name="ruler" >
  <xsl:with-param name="level" select="'1'"/>
  </xsl:call-template>  
 </div>
 <br />
</xsl:for-each>
</xsl:for-each>
</xsl:template>

<xsl:template match="ruler" name="ruler">
<xsl:param name="level"/>
 <p style="text-indent:{$level}em">
 type:<xsl:value-of select="@type"/>,
 cmp:<xsl:value-of select="@cmp"/>,
 value:<xsl:value-of select="@value"/>;
 </p>
 <xsl:apply-templates select="ruler">
  <xsl:with-param name="level" select="$level + 2"/>
 </xsl:apply-templates>
</xsl:template>

</xsl:stylesheet>


============================
============================</code>

用递归实现了分层的效果。代码还是乱了点有模板和for-each穿插!


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