小编sri*_*tsa的帖子

如何使用XSL检查XML文件中是否存在属性

在运行时,我可以有两种格式的XML文件:

  1. <root>
        <diagram> 
            <graph color= "#ff00ff">    
                <xaxis>1 2 3 12 312 3123 1231 23 </xaxis>
                <yaxis>1 2 3 12 312 3123 1231 23 </yaxis>
            </graph>  
        </diagram> 
    </root>
    
    Run Code Online (Sandbox Code Playgroud)
  2. <root>
        <diagram> 
            <graph>    
                <xaxis>1 2 3 12 312 3123 1231 23 </xaxis>
                <yaxis>1 2 3 12 312 3123 1231 23 </yaxis>
            </graph>  
        </diagram> 
    </root>
    
    Run Code Online (Sandbox Code Playgroud)

根据颜色属性的存在,我必须处理xaxis和yaxis的值.

我需要使用XSL来做到这一点.任何人都可以帮我暗示我可以检查这些条件的片段.

我试过用

<xsl: when test="graph[1]/@color">
     //some processing here using graph[1]/@color values
</xsl:when>
Run Code Online (Sandbox Code Playgroud)

我收到了一个错误......

xml xslt xpath

27
推荐指数
3
解决办法
7万
查看次数

标签 统计

xml ×1

xpath ×1

xslt ×1