0

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

user898465
  • 944
  • 1
  • 12
  • 23
  • And as an extension how this, how would you do an exclusive select, ie if the node for 'one' exists don't select node 'three', but if node for 'one' doesn't exist then select 'three' in the nodeset? – user898465 Dec 15 '14 at 16:31

1 Answers1

1

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.

michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
  • Thanks for the answer, I'm a bit of a beginner with xsl. What I meant by the extension question was is it possible to do more specific selects. For example out of the nodeset above if you want to check the existence of one node as a condition of selecting another? Say for example you want IF one EXISTS THEN nodeset should contain three and if doesn't then it shouldn't – user898465 Dec 15 '14 at 16:58
  • I suppose there are several ways to express it, here's one: `$bSet[not(C='three' and not(../B/C='one'))]`. – michael.hor257k Dec 15 '14 at 17:10
  • Note that you have tagged this as XSLT, but your questions are about XPath. In XSLT, you can "delete" a node by matching it specifically. – michael.hor257k Dec 15 '14 at 17:13