*********************请教一个xslt的问题**********************
请教一个问题。我要在xslt里显示和当前节点的某属性值相同的另外一个节点的另外一个属性值比如
<deal>
<begin>
<seat SeatNo="1" cards="1,2,3,4,5,6" />
<seat SeatNo="2" cards="1,2,3,4,5,6" />
<seat SeatNo="3" cards="1,2,3,4,5,6" />
</begin>
<players>
<seat SeatNo="1" playerid="user01">
<seat SeatNo="2" playerid="user02">
<seat SeatNo="3" playerid="user03">
</players>
</deal>
当前节点为begin/seat 我想要根据id=1查找players下的id为1的节点,并显示该节点的name属性
请问这个xslt表达式应该怎么写啊
我现在是这样写的
/Deal/Players/Seat[@SeatNo=./@SeatNo]/@PlayerID" />
可是不管SeatNo是1,2,3显示的都是user01
--------------------编程问答-------------------- 顶 --------------------编程问答-------------------- 顶 --------------------编程问答-------------------- 帮忙啊 --------------------编程问答-------------------- ding --------------------编程问答-------------------- test.xml
<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<deal>
<begin>
<seat SeatNo="1" cards="1,2,3,4,5,6" />
<seat SeatNo="2" cards="1,2,3,4,5,6" />
<seat SeatNo="3" cards="1,2,3,4,5,6" />
</begin>
<players>
<seat SeatNo="1" playerid="user01"/>
<seat SeatNo="2" playerid="user02"/>
<seat SeatNo="3" playerid="user03" />
</players>
</deal>
test.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="/">
<xsl:for-each select="//begin/seat">
<xsl:variable name="id" select="@SeatNo"/>
Begin_SeatNo:<xsl:value-of select="$id"/> Player_playerID <xsl:value-of select="//players/seat[@SeatNo=$id]/@playerid"/><br/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
结果
Begin_SeatNo:1 Player_playerID user01--------------------编程问答-------------------- 或者
Begin_SeatNo:2 Player_playerID user02
Begin_SeatNo:3 Player_playerID user03
test.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="//begin/seat">
<xsl:variable name="id" select="@SeatNo"/>
Begin_SeatNo:<xsl:value-of select="$id"/> Player_playerID <xsl:value-of select="//players/seat[@SeatNo=$id]/@playerid"/><br/>
</xsl:template>
</xsl:stylesheet>
或者
test.xsl
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
<xsl:template match="//begin/seat">
Begin_SeatNo:<xsl:value-of select="@SeatNo"/>
Player_playerID <xsl:call-template name="getName"><xsl:with-param name="id" select="@SeatNo"/></xsl:call-template><br/>
</xsl:template>
<xsl:template name="getName">
<xsl:param name="id"/>
<xsl:value-of select="//players/seat[@SeatNo=$id]/@playerid"/>
</xsl:template>
</xsl:stylesheet>
写法很多,我不一一写了。 --------------------编程问答-------------------- jf
补充:.NET技术 , ASP.NET