this is my xml:

</ROOT>
<Item Segment="COMFIN" Dept="Blackberry" Category1="Active Directory" Category2="Password Reset" Code="Reset" />
<Item Segment="GEHC" Dept="Remote Support" Category1="Hardware" Category2="Cable" Code="Replace" />
<Item Segment="Plastics" Dept="Blackberry" Category1="Software" Category2="Casing" Code="Install" />
<Item Segment="Plastics" Dept="Remote Support" Category1="Hardware" Category2="Casing" Code="Repair" />
<Item Segment="Plastics" Dept="Site Support" Category1="Hardware" Category2="Parts &amp; Vendor 5.0" Code="Replace" />
</ROOT>

this is my query:

"/ROOT/Item[@Dept='Site Support' and not(@Category1=preceding::Item/@Category1)]/@Category1"
returns nothing

for those of you that it isn't plain to see, i'm attempting to select all Item nodes that have a attrib of Dept/with value of Site Support, and also, the preceding nodes must not have duplicate category1 values.
then the query gets the category1 attribute nodes from the Item nodes.

This does not work correctly on this expression, but it does here:

"/ROOT/Item[@Dept='Blackberry' and not(@Category1=preceding::Item/@Category1)]/@Category1"
returns active directory, and software

my assumption is that the reason that i get no results on the first query is that there is only one dept attribute with the site support value, and because of the way that i've formatted my query string, it removes the nodes that it finds in the first expression when it test's the second expression. that's my guess though..

any help? please?

Member Avatar for gravyboat

It's because you're asking for "all Item nodes that have a attrib of Dept/with value of Site Support, and also, the preceding nodes must not have duplicate category1 values."

"/ROOT/Item[@Dept='Site Support' and not(@Category1=preceding::Item/@Category1)]/@Category1"

In XSLT 1.0, this means that *any* preceding node that has a matching @Category1 value will be excluded (maybe you meant to ask that only the *immediately* preceding be excluded?).

The reason that

/ROOT/Item[@Dept='Blackberry' and not(@Category1=preceding::Item/@Category1)]/@Category1"

returns "Active Directory" and "Software" is that these are the only nodes who have no preceding sibling with that attribute value (they are unique in the XML document).

I would suggest you read the XSLT FAQ here: http://www.dpawson.co.uk/xsl/sect2/sect21.html

And look into XSLT 2.0 so that you can use expressions like

/ROOT/Item[@Dept='Blackberry' and not(@Category1=preceding::Item[B][1][/B]/@Category1)]/@Category1"

assuming that this is what you're trying to do.

Hope this helps,
John

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.