Search code examples
xslt-1.0node-set

remove from xsl nodeset


Say you have a document like this:

<A>
    <B>
        <C>one</C>
    </B>
    <B>
        <C>two</C>
    </B>         
    <B>
        <C>three</C>
    </B>
</A>

You then use xsl to create a nodeset of B nodes

<xsl:variable name="bSet" select="//A/B"/>

You now have this:

    <B>
        <C>one</C>
    </B>
    <B>
        <C>two</C>
    </B>         
    <B>
        <C>three</C>
    </B>

What is the accepted method for deleting a a particular set of nodes from this nodeset in xsl 1.0? For example you only want B's with a C that is either 'one' or 'two', but not 'three' like this?

    <B>
        <C>one</C>
    </B>
    <B>
        <C>two</C>
    </B>

How might you do this in xsl, with a more exclusve selector r can you delete from the nodeset after you have declared it(ie, is it dynamic lie a java Arraylist)?


Solution

  • The expression:

    $bSet[not(C='three')]
    

    selects:

    <B>
        <C>one</C>
    </B>
    <B>
        <C>two</C>
    </B>
    

    I am afraid I didn't understand your "extension" question.