2012-12-10 13 views
32

Krótkie pytanie: Chciałbym wybrać wszystkie węzły, które nie pasują do atrybutu (@type! = 'X'), ale także atrybut doesnt exist (??). Obecnie im nic nie odzyskuje, ponieważ inne węzły nie mają żadnego atrybutu.xpath wybierz według atrybutu, gdy atrybut nie istnieje

Tło: Mam trochę XML. Zauważ, że jeden ma typ = "feature", ale wszystkie inne nie mają atrybutu "type".

<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> 

I styl 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> 

Dzięki za czas.

Odpowiedz

51

Poniższy kod będzie wybrać wszystkie węzły, gdzie atrybut typ nie istnieje:

select="image[not(@type)]" 

dodać tę logikę w kodzie.

+0

dość łatwe. dzięki za wskaźnik. –

11

Spróbuj użyć not() zamiast != w orzecznika ...

<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>