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.










share|improve this question






















  • 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















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.










share|improve this question






















  • 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













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.










share|improve this question













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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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


















  • 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












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.






share|improve this answer





















  • 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











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















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

























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.






share|improve this answer





















  • 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















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.






share|improve this answer





















  • 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













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.






share|improve this answer












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.







share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 9 at 19:49









wp78de

9,77951738




9,77951738












  • 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










  • 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


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














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





















































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







這個網誌中的熱門文章

Tangent Lines Diagram Along Smooth Curve

Yusuf al-Mu'taman ibn Hud

Zucchini