xsl:for-each中引用循环外全局变量

本文介绍了一种使用XSLT进行网页元素选择的方法,通过定义全局变量与参数来实现对特定类型数据的选择与展示。具体展示了如何根据不同条件为页面元素添加样式并进行数据绑定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

//全局变量

<xsl:variable name="temp_driving_type" select="WebPage/Data/OptReturnData[@OptRetName='GetEmpCarById']/OptRetData/NewDataSet/Table/driving_type"/>
<select class="Input" name="driving_type" id="driving_type">
<xsl:for-each select="WebPage/Data/OptReturnData[@OptRetName='GetEmpCarTypeNames']/OptRetData/NewDataSet/Table">
<xsl:choose>
<xsl:when test="contains($temp_driving_type,id)">
<option value="{id}" selected ="selected">
<xsl:value-of select="name"/>
</option>
</xsl:when>
<xsl:otherwise>
<option value="{id}">
<xsl:value-of select="name"/>
</option>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</select>

 

//全局参数

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1">

<xsl:template match="/">
<xsl:param name="temp_types" select="WebPage/Data/OptReturnData[@OptRetName='GetEmpCarTypeNames']/OptRetData/NewDataSet"></xsl:param>

<xsl:for-each select="WebPage/Data/OptReturnData[@OptRetName='QueryEmpCarList']/OptRetData/NewDataSet/Rows">
<xsl:if test="(position() mod 2)=0">
<xsl:attribute name="class">Hover Bj</xsl:attribute>
</xsl:if>

<xsl:variable name="temp_driving_type" select="driving_type"/>
<xsl:for-each select="$temp_types/Table">
<xsl:choose>
<xsl:when test="contains($temp_driving_type,id)">
<option value="{id}" selected ="selected">
<xsl:value-of select="name"/>
</option>
</xsl:when>
</xsl:choose>
</xsl:for-each>

</xsl:for-each>

</xsl:template>
</xsl:stylesheet>


个人博客地址:http://www.iwooto.com

转载于:https://www.cnblogs.com/whoyou/p/5053389.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值