2014-12-11 4 views
0

Возьмите список ошибокРазметка списка элементов на основе динамических критериев

<?xml version="1.0"?> 
<bugs> 
    <bug> 
    <status>todo</status> 
    <content> this is a todo bug </content> 
    </bug> 

    <bug> 
    <status>closed</status> 
    <content>this is a closed bug</content> 
    </bug> 

    <bug> 
    <status>new</status> 
    <content>this is a new bug</content> 
    </bug> 

    <bug> 
    <status>deferred</status> 
    <content>this is a deferred bug</content> 
    </bug> 

    <bug> 
    <status>todo</status> 
    <content>this is another todo bug</content> 
    </bug> 

</bugs> 

Что бы в XSLT, который будет перечислять определенный набор «активных» ошибок и все остальные?

я смог построить «активную» половину этого вопроса, основанное на отличном ответ Приводимые здесь: XSLT: Using variables in a key function, который был бы следующий XSLT:

<?xml version="1.0"?> 
<xsl:stylesheet version="1.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
       xmlns:ext="http://exslt.org/common" 
       > 

    <xsl:output method="text"/> 

    <xsl:param name="pActive"> 
    <!-- this is supposed to be the dynamic criteria --> 
    <a>todo</a> 
    <a>new</a> 
    </xsl:param> 

    <xsl:key name="kBugsByStatus" match="bug" use="normalize-space(status)"/> 

    <xsl:variable name="vActive" select="ext:node-set($pActive)/*"/> 

    <xsl:template match="/"> 
    <xsl:text>Active bugs:&#xA;</xsl:text> 
    <xsl:apply-templates select="key('kBugsByStatus',$vActive)"/> 

    <xsl:text>Other bugs:&#xA;</xsl:text> 
    <!-- This is the question: --> 
    <xsl:apply-templates select="key('kBugsByStatus',???)"/> 

    </xsl:template> 


    <xsl:template match="bug"> 
    <xsl:text>* </xsl:text> 
    <xsl:value-of select="normalize-space(content)"/> 
    <xsl:text>&#xA;</xsl:text> 
    </xsl:template> 

</xsl:stylesheet> 

Спасибо!

+0

И ваш ожидаемый результат выглядит? –

ответ

0

Использование select="/bugs/bug[not(status = $vActive)]".

+0

ах спасибо! читать книги :). Существует ли «ключевой» способ, но для лучшего понимания ... – sly

+1

Вы можете настроить ключ для другого направления с помощью < ', а затем с помощью XSLT 2.0 вы можете использовать' select = "/ bugs/bug [not (key ('kSearch', status, $ pActive))]". С XSLT 1.0 третий аргумент функции 'key' для изменения контекста не поддерживается, поэтому он становится немного уродливым с' 'и' '. –

Смежные вопросы