XSLT professional site
  首 页 经典书籍 精彩实例 热门文章 语法详解 休闲天地  
题目:

<root> <item id="1" parent="0" /> <item id="2" parent="1" /> <item id="3" parent="2" /> <item id="4" parent="1" /> </root> 显示出目标示例中某个节点的父节点,由父节点向子节点排列. 例如.得到一个<root id='3'/>的XML文件,以及一个 目标示例 (可以用Document函数打开, 本演示用上面的示例做,就是树状那个).(filename:tree.xml) 那么输出的结果就是:1 - 2 - 3.
实现:

<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:key name="searchid" match="item" use="@id"/> <xsl:template match="/"> <xsl:call-template name="print-path"> <xsl:with-param name="sid" select="'3'"/> </xsl:call-template> </xsl:template> <xsl:template name="print-path"> <xsl:param name="sid" select="'0'"/> <xsl:for-each select="key('searchid',$sid)/ancestor-or-self::*"> <xsl:value-of select="@id"/> </xsl:for-each> </xsl:template> </xsl:stylesheet>
<上一篇    下一篇>
Email: xslt.org.cn@gmail.com

© 2007     xslt.org.cn