Подтвердить что ты не робот

Xpath выбирает по атрибуту, когда attitute not present

Короткий вопрос: Я хотел бы выбрать все узлы, которые не соответствуют атрибуту (@type!= 'X'), но также атрибут не существует (??). В настоящее время im не получает ничего назад, потому что другие узлы вообще не имеют атрибута.

Фон: У меня есть 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>

И стиль 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>

Спасибо за время.

4b9b3361

Ответ 1

Следующий код выберет все узлы, где атрибут типа не существует:

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

Добавьте эту логику в свой код.

Ответ 2

Попробуйте использовать 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>