How do I detect duplicates subnodes with several nodes with XQuery
up vote
1
down vote
favorite
How can I find duplicate subnodes with XQuery and/or XPath, my XML structure looks like this:
<register>
<operator referenceid="1">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="2">
<operationpart>
<type>Category_code</type>
<name>202020</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Development</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>2</name>
</operationpart>
</operator>
<operator referenceid="3">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="4">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
<operator referenceid="5">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
</register>
Two should get listed in a result as duplicates, that is 4 and 5, also 1 and 3.
XQuery/Xpath should also ignore the attribute referenceid which always must be unique in the XML-list.
xpath xquery
add a comment |
up vote
1
down vote
favorite
How can I find duplicate subnodes with XQuery and/or XPath, my XML structure looks like this:
<register>
<operator referenceid="1">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="2">
<operationpart>
<type>Category_code</type>
<name>202020</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Development</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>2</name>
</operationpart>
</operator>
<operator referenceid="3">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="4">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
<operator referenceid="5">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
</register>
Two should get listed in a result as duplicates, that is 4 and 5, also 1 and 3.
XQuery/Xpath should also ignore the attribute referenceid which always must be unique in the XML-list.
xpath xquery
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48
add a comment |
up vote
1
down vote
favorite
up vote
1
down vote
favorite
How can I find duplicate subnodes with XQuery and/or XPath, my XML structure looks like this:
<register>
<operator referenceid="1">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="2">
<operationpart>
<type>Category_code</type>
<name>202020</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Development</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>2</name>
</operationpart>
</operator>
<operator referenceid="3">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="4">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
<operator referenceid="5">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
</register>
Two should get listed in a result as duplicates, that is 4 and 5, also 1 and 3.
XQuery/Xpath should also ignore the attribute referenceid which always must be unique in the XML-list.
xpath xquery
How can I find duplicate subnodes with XQuery and/or XPath, my XML structure looks like this:
<register>
<operator referenceid="1">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="2">
<operationpart>
<type>Category_code</type>
<name>202020</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Development</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>2</name>
</operationpart>
</operator>
<operator referenceid="3">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
<operationpart>
<type>Big_code</type>
<name>1</name>
</operationpart>
</operator>
<operator referenceid="4">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
<operator referenceid="5">
<operationpart>
<type>Category_code</type>
<name>101010</name>
</operationpart>
<operationpart>
<type>Category_text</type>
<name>Accounting</name>
</operationpart>
</operator>
</register>
Two should get listed in a result as duplicates, that is 4 and 5, also 1 and 3.
XQuery/Xpath should also ignore the attribute referenceid which always must be unique in the XML-list.
xpath xquery
xpath xquery
asked Nov 9 at 15:42
Roxpace
61
61
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48
add a comment |
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
Kinda hard to put this in a list; how about showing the duplicate nodes:
/register/*
[normalize-space(.) = preceding-sibling::*/normalize-space(.)
and
not(normalize-space(.) = following-sibling::*/normalize-space(.))
]
Demo, which returns the node with referenceid
3 and 5.
or the opposite, to return 1 and 4:
/register/*
[normalize-space(.) = following-sibling::*/normalize-space(.)
and
not(normalize-space(.) = preceding-sibling::*/normalize-space(.))
]
If needed, you can combine both with an |
operator.
It's up to you. Obviously, this case can be further simplified.
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Kinda hard to put this in a list; how about showing the duplicate nodes:
/register/*
[normalize-space(.) = preceding-sibling::*/normalize-space(.)
and
not(normalize-space(.) = following-sibling::*/normalize-space(.))
]
Demo, which returns the node with referenceid
3 and 5.
or the opposite, to return 1 and 4:
/register/*
[normalize-space(.) = following-sibling::*/normalize-space(.)
and
not(normalize-space(.) = preceding-sibling::*/normalize-space(.))
]
If needed, you can combine both with an |
operator.
It's up to you. Obviously, this case can be further simplified.
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
add a comment |
up vote
0
down vote
Kinda hard to put this in a list; how about showing the duplicate nodes:
/register/*
[normalize-space(.) = preceding-sibling::*/normalize-space(.)
and
not(normalize-space(.) = following-sibling::*/normalize-space(.))
]
Demo, which returns the node with referenceid
3 and 5.
or the opposite, to return 1 and 4:
/register/*
[normalize-space(.) = following-sibling::*/normalize-space(.)
and
not(normalize-space(.) = preceding-sibling::*/normalize-space(.))
]
If needed, you can combine both with an |
operator.
It's up to you. Obviously, this case can be further simplified.
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
add a comment |
up vote
0
down vote
up vote
0
down vote
Kinda hard to put this in a list; how about showing the duplicate nodes:
/register/*
[normalize-space(.) = preceding-sibling::*/normalize-space(.)
and
not(normalize-space(.) = following-sibling::*/normalize-space(.))
]
Demo, which returns the node with referenceid
3 and 5.
or the opposite, to return 1 and 4:
/register/*
[normalize-space(.) = following-sibling::*/normalize-space(.)
and
not(normalize-space(.) = preceding-sibling::*/normalize-space(.))
]
If needed, you can combine both with an |
operator.
It's up to you. Obviously, this case can be further simplified.
Kinda hard to put this in a list; how about showing the duplicate nodes:
/register/*
[normalize-space(.) = preceding-sibling::*/normalize-space(.)
and
not(normalize-space(.) = following-sibling::*/normalize-space(.))
]
Demo, which returns the node with referenceid
3 and 5.
or the opposite, to return 1 and 4:
/register/*
[normalize-space(.) = following-sibling::*/normalize-space(.)
and
not(normalize-space(.) = preceding-sibling::*/normalize-space(.))
]
If needed, you can combine both with an |
operator.
It's up to you. Obviously, this case can be further simplified.
answered Nov 9 at 19:49
wp78de
9,52651638
9,52651638
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
add a comment |
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
Thanks a lot @wp78de, looks promising, is it possible to show all duplicates lines in the result? Like not only referenceid 3 and 5 but also which they duplicates like 1,3 and 4,5 so I get a complete list what duplicates? Also is it possible also to make this with XQuery?
– Roxpace
Nov 11 at 16:44
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
I also tried to add more duplicates with same values and this only shows the last duplicate, little tough to detect all duplicates if I always only see the last duplicates and not everyone
– Roxpace
Nov 11 at 16:57
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53228887%2fhow-do-i-detect-duplicates-subnodes-with-several-nodes-with-xquery%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
it is not quite clear what counts as a duplicate subnode from your question. Could you add a sample of the output that you wish to generate. You can probably remove elements with referenceid 4 and 5 from your input sample, to make things more readable.
– duncdrum
Nov 9 at 15:58
Thanks for the comment @duncdrum, the example should be clear, but I can result I wanna get produced after looking for duplicates. referenceid 4, referenceid 5 referenceid 1, referenceid 3 I wanna detect a combination of elements which are duplicates, wanna compare in the level <operator> and detect if other <operator> content are the same except for the attribute which always are unique.
– Roxpace
Nov 9 at 16:42
I do not wanna remove, I wanna see what is duplicates.
– Roxpace
Nov 9 at 16:48