XML 有 nodes set 和 attributes, 他们是不同的。 最近在作一个xsl 的style sheet, 想检查node中是不是有某个attribute,试了好多的方式和函数,就是不work, 最后发现混淆了这两个东西, node和attribute。

XML data file:

…<COPs> 
        <COP description="#1System License" max="1" min="0" name="A01" relevantForSoftware="false" value="1"/> 
        <COP description="#2System License" max="1" min="0" name="A02" relevantForSoftware="false" value="1"/>

        <COP description="#2System License" name="A03" relevantForSoftware="false"> 
     COPs>

 

想判断

if “value”  is there

do something

  else

do something else

end if

 

有好多地方谈如何检查child node, 用了都不好用,这些事用来检测node的, 不是attribute。

<xsl:if test="*">
  Only node1 can pass the if condition
xsl:if> 

<xsl:template match="node">
 do stuff for node
  <xsl:apply-templates select="*[*]"/>
xsl:template>
 
正确的是
<xsl:when test="@value">
do something here
xsl:if>
 
 
非常重要是这个“@”, 是操作attribute的。 
忙活了大半晌,悟出来的。不管理论对不对,我的程序转的很好。