有关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]" />的时候,取不到对应的值造成,但我不知道怎么判断这个值
...全文
17 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
snowcloud2002 2004-03-20
  • 打赏
  • 举报
回复
:)
yphui18 2004-03-20
  • 打赏
  • 举报
回复
支持思归老大
saucer 2004-03-20
  • 打赏
  • 举报
回复
test if it exists:

<xsl:variable name="ValName" select="../../row/*[name() = $Dname]" />
<xsl:choose>
<xsl:when test="not ($ValName)">
doesn't exist
</xsl:when>
<xsl:when test="$DvalueType = 1">
......

8,906

社区成员

发帖
与我相关
我的任务
社区描述
XML/XSL相关问题讨论专区
社区管理员
  • XML/XSL社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧