首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

请问有关XSL中变量传递的有关问题

2012-02-03 
请教有关XSL中变量传递的问题最近在学习XSL,遇到这么个问题:XML:[code] document......issueid 1

请教有关XSL中变量传递的问题
最近在学习XSL,遇到这么个问题:

XML:
[code] <document>
        ......
        <issue   id= "1 ">
                <title> Test   Issue   1 </title>
                <status> 2 </status>
        </issue>
        <issue   id= "2 ">
                <title> Test   Issue   2 </title>
                <status> 0 </status>
        </issue>
        <issue   id= "3 ">
                <title> Test   Issue   3 </title>
                <status> 1 </status>
        </issue>
        ......
</document> [/code]

现在想用XSL来构建表格,内容是这样:
XSL:
[code] <xsl:template   match= "issue ">
<tr>
        <td> <xsl:value-of   select= "title "   /> </td>
</tr>
</xsl:template> [/code]

不过,我想让td的class根据status的不同而不同,想了半天除了 <xsl:choose> 整个语句外,不知道能不能用 <xsl:param> 或 <xsl:variable> 来定义一个变量,只choose变量,然后应用到td去。结果看起来应该像这样:
[code] <tr>
        <td>
                <xsl:attribute   name= "class "> 被选定的class名称 </xsl:attribute>
                <xsl:value-of   select= "title "   />
        </td>
</tr> [/code]

这个思路对吗?代码上如何实现呢?

多谢赐教!

[解决办法]
可以看看这个是否合适
http://dotnet.aspx.cc/article/yawo3qgm-xd53-4d3d-oybr-blsbx5bngaym/read.aspx
[解决办法]
<xsl:template name= "selectclass ">
<xsl:param name= "status ">
<xsl:choose>
<xsl:when test= "$status= '1 ' ">
<xsl:text> 11111 </xsl:text>
</xsl:when>
<xsl:when test= "$status= '2 ' ">
<xsl:text> 22222 </xsl:text>
</xsl:when>
<xsl:choose>
</xsl:template>
好像还是用CHOOSE了,总要把STATUS和CLASSNAME有个对应的关系吧?
[解决办法]

<xsl:variable name= "myvar " select= "abc " />
The variable is global if it 's declared as a top-level element, and local if it 's declared within a template.
qqhe325说的方法,如果这样,是不是就要在 <xsl:attribute name= "class "> </xsl:attribute> 之间加上 <xsl:call-template name= "selectclass " /> 呢?是的

热点排行