以文本方式查看主题

-  中文XML论坛 - 专业的XML技术讨论区  (http://bbs.xml.org.cn/index.asp)
--  『 XSL/XSLT/XSL-FO/CSS 』  (http://bbs.xml.org.cn/list.asp?boardid=8)
----  [求助]关于xsl:apply-templates嵌套的问题  (http://bbs.xml.org.cn/dispbbs.asp?boardid=8&rootid=&id=126135)


--  作者:天佑我中华
--  发布时间:4/6/2013 11:27:00 PM

--  [求助]关于xsl:apply-templates嵌套的问题

<xsl:apply-templates select="/XML_User/List/Record[@Groups ='3']" ></xsl:apply-templates>

如何把'3'替换成类似于@Groups这样的参数

具体的实例如下,Groups=1表示这个是一个组,0表示普通用户,大于1表示该用户所加入的组ID
输出用户列表,先显示1(组),再显示0(用户)
输出1(组)的时候,再执行一次templates ,目的是输出该组下的所有用户,条件就是所有用户的Groups=组的ID

<xsl:template match="/XML_User/List">
 <table width="100%" border="0" cellpadding="3" cellspacing="0" id="Content">
 <tr class="LineBg">
 <th width="8%" >编号</th>
 <td width="12%">用户名称</td>
 <td width="12%">登陆账号</td>
 <th>所拥有的权限范围</th>
 <th width="20%">操作</th>
 </tr>
 <xsl:apply-templates select="/XML_User/List/Record[@Groups ='1']" ></xsl:apply-templates>
 <xsl:apply-templates select="/XML_User/List/Record[@Groups ='0']" ></xsl:apply-templates>
 </table>
</xsl:template>

<xsl:template match="/XML_User/List/Record">
<tr>
<xsl:choose>
<xsl:when test="position() mod 2 = 1"><xsl:attribute name="style">background-color:#FFFFFF;</xsl:attribute></xsl:when>
<xsl:otherwise><xsl:attribute name="style">background-color:#EEEEEE;</xsl:attribute></xsl:otherwise>
</xsl:choose>
<xsl:if test="../../@LoginName=@LoginName"><xsl:attribute name="style">background-color:#FFDDFF;</xsl:attribute></xsl:if>
<th><xsl:value-of select="@ID"   /></th>
<td><xsl:value-of select="@RealName" /></td>
<td><xsl:value-of select="@LoginName" /></td>
<td style="letter-spacing:1px;"><xsl:value-of select="."  /></td>
<th>
<button onClick="Admin_User.Modify({@ID});">修改</button>
<button onClick="Admin_User.Delete({@ID});">删除</button>
<xsl:if test="@Groups='1'">
<button onClick="Admin_User.Groups({@ID});">展开</button>
</xsl:if>
</th>
</tr>
<xsl:if test="@Groups='1'">
<xsl:apply-templates select="/XML_User/List/Record[@Groups ='3']" ></xsl:apply-templates>
</xsl:if>
</xsl:template>


--  作者:Qr
--  发布时间:4/7/2013 9:44:00 AM

--  
用变量代替@Groups

<xsl:apply-templates select="/XML_User/List/Record[@Groups ='{...}']" ></xsl:apply-templates>

N年不用XSLT,只能这么提示了,希望对你有帮助。


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