简短的问题:我想选择与属性不匹配的所有节点(@type!='x'),但属性也不存在(??).目前,我什么也没收到,因为其他节点根本没有属性.
背景:我有一些XML.请注意,其中一个具有type ="feature",但所有其他都没有'type'attr.
<image type="feature"><description>X</description><url>media/designer_glass_tile_04.jpg</url><height></height><width/></image>
<image><description>Designer Glass 05</description><url>media/designer_glass_tile_05.jpg</url><height></height><width/></image>
<image><description>Designer Glass 06</description><url>media/designer_glass_tile_06.jpg</url><height></height><width/></image>
<image><description>Designer Glass 07</description><url>media/designer_glass_tile_07.jpg</url><height></height><width/></image>
<image><description>Designer Glass 08</description><url>media/designer_glass_tile_08.jpg</url><height></height><width/></image>
Run Code Online (Sandbox Code Playgroud)
和XSL风格:
<div id="gallery">
<div id="feature" >
<xsl:apply-templates select="image[@type='feature']"/>
</div>
<div id="thumbs">
<xsl:apply-templates select="image[@type!='feature']"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
RAT*_*THI 74
以下代码将选择type属性不存在的所有节点:
select="image[not(@type)]"
Run Code Online (Sandbox Code Playgroud)
在代码中添加此逻辑.
Dan*_*ley 12
尝试使用not()
而不是!=
在谓词中...
<div id="gallery">
<div id="feature" >
<xsl:apply-templates select="image[@type='feature']"/>
</div>
<div id="thumbs">
<xsl:apply-templates select="image[not(@type='feature')]"/>
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
34496 次 |
最近记录: |