misterbear
misterbear

Reputation: 833

Match and display missing node in XSL

I have to match one set of nodes to another set of nodes to see which one is missing. And when it is missing, I need to display the name of the missing node. Can only use XSLv1.0.

XML:

<root>
  <ph>
    <wb>full_list</wb>
      <wbs>
        <categories>
          <rule>
            <name>Intimate Clothing</name>
            <value>95</value>
            <allow/>
            <log>true</log>
          </rule>
          <rule>
            <name>Books</name>
            <value>825</value>
            <allow/>
            <log>true</log>
          </rule>
          <rule>
            <name>Violence</name>
            <value>93</value>
            <allow/>
            <log>true</log>
          </rule>
      </categories>
    </wbs>
  </ph>
          ... hundreds of lines later ...
  <ph>
    <wb>items</wb>
      <wbs>
        <categories>
          <rule>
            <value>93</value>
            <allow/>
            <log>true</log>
          </rule>
          <rule>
            <value>95</value>
            <allow/>
          <log>true</log>
        </rule>
      </categories>
    </wbs>
  </ph>
</root>

Desired Result:

Books <-- because "Books" is the missing one from the two sets of nodes (or value "825").

The XSL I have:

    <xsl:variable name="ph" select="root/ph"/>

    <xsl:for-each select="$ph[wb = 'full_list']/wbs/categories/rule[value != $ph[wb = 'items']/wbs/categories/rule/value]">
        <xsl:value-of select="name"/>
    </xsl:for-each>

But this just ends up displaying every <name> on the full_list. It should only display "Books". What am I doing wrong?

Upvotes: 0

Views: 329

Answers (1)

michael.hor257k
michael.hor257k

Reputation: 117018

The reason why your method does not work is that you are using node[child!=node-set] instead of node[not(child=node-set)]. The first construct says "every node that has at least one child that does not match some member of node-set"; the second one says "every node that has no child that matches any member of node-set".

I repeat my recommendation to use a key, which is more efficient in finding "related" items.

Upvotes: 1

Related Questions