有关xsl的问题,请各位大侠帮忙
leneq 2004-03-19 04:12:20 以下是我的xsl文件,主要目的是比较同一个xml文件里面不同节点的值
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:template match="/">
<xsl:element name = "form1">
<xsl:for-each select="data/form1/field">
<xsl:variable name="Dname" select="@Dname" />
<xsl:variable name="DvalueType" select="@DvalueType"/>
<xsl:variable name="Dvalue" select="@Dvalue"/>
<xsl:variable name="ValName" select="../../row/*[name() = $Dname]" />
<xsl:choose>
<xsl:when test="$DvalueType = 1">
<xsl:choose>
<xsl:when test="($ValName - $Dvalue) != 0">
<xsl:element name="field">
<xsl:attribute name="Dname">
<xsl:value-of select="$Dname"/>
</xsl:attribute>
<xsl:attribute name="DvalueNew">
<xsl:value-of select="$Dvalue"/>
</xsl:attribute>
<xsl:attribute name="DvalueOld">
<xsl:value-of select="$ValName"/>
</xsl:attribute>
<xsl:attribute name="DvalueType">
<xsl:value-of select="$DvalueType"/>
</xsl:attribute>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:choose>
<xsl:when test="$ValName != $Dvalue">
<xsl:element name="field">
<xsl:attribute name="Dname">
<xsl:value-of select="$Dname"/>
</xsl:attribute>
<xsl:attribute name="DvalueNew">
<xsl:value-of select="$Dvalue"/>
</xsl:attribute>
<xsl:attribute name="DvalueOld">
<xsl:value-of select="$ValName"/>
</xsl:attribute>
<xsl:attribute name="DvalueType">
<xsl:value-of select="$DvalueType"/>
</xsl:attribute>
</xsl:element>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
如下xml文件
<data>
<row>
<Var_qyname>b1</Var_qyname>
</row>
<form1>
<field Dname="Var_qyname" Dvalue="a1" DvalueType="0"/>
<field Dname="Var_name" Dvalue="a2" DvalueType="0"/>
<field Dname="Num_alltotal" Dvalue="0" DvalueType="1"/>
</form1>
</data>
我的目的是比较form1和row节点
通过以上xsl文件我可以知道Var_qyname 从b1 变到 a1
可是当比较Var_name和Num_alltotal时,因为此两项在row节点里没有,Var_name的改变值得不到,而Num_alltotal得到0。
我想可能是在row节点里没有对应节点造成的,在<xsl:variable name="ValName" select="../../row/*[name() = $Dname]" />的时候,取不到对应的值造成,但我不知道怎么判断这个值