• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Differences in XML outputs when transforming XML using both XMLSpy and Java

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the following XML:



And I want to remove the duplicate records from the XML that contain the same <TITLE> and <ARTIST> elements so that I end up with the following XML output:



The expected output works when I use the following stylesheet on the XML and transform it using XML Spy:



However when I pass this transformation to my Java code, the duplicates are removed however the last record within my XML is also removed. I have tried this with different XML files and it always removes the duplicates along with the last record - I have no idea why the last record is also being removed.

My Java code is as follows:



Has anyone got any idea as to why when I transform the XML using XMLSpy it works but when I transform the XML using my Java code the last record is being removed?

Thanks in advance
 
Ranch Hand
Posts: 734
7
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[0] Bear in mind that dom4j is very much lacking continuous support and dated, unfortunately for those who like it as it has certainly its own merit.

[1] The problem certainly stamps from the outdated/incomplete/not-fully-debugged implement of xpath/xslt engine. The xmlspy rendering based on your description is certainly a better or a more to-date interpretation of the recommendation. A hack to remedy the dated implementation is to add a node-test condition on the existence of following::CD. Like this.

[1.1] Though it should make it work, this is not what I would recommend anyone doing because that would induce one to learn it the wrong way.

[2] What you could do is simply download or make yourself available the new xalan-j, say from Apache such as 2.7.x+, and make its jars in the classpath setup. The main needed jars are xml-api.jar, xalan.jar and xercesImpl.jar if you want to be more specific. After that, the xslt should function correctly without the hack shown in [1].

[3] Just a side-note, the xslt would not complete deliver what you seem to suggest it doing because the identified following::CD may not be the same in the node-test(s). But that's another story not of the  immediate concern.
 
John Paul Hoey
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Tsuji,

It was indeed what you suggested. I downloaded and added the most recent .jars as you suggested and it worked as expected.

Thanks again for taking the time out to help me which is really appreciated.
 
I guess everyone has an angle. Fine, what do you want? Just know that you cannot have this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic