Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simplifying XML parents

Status
Not open for further replies.

FrozenGrapes

Programmer
Joined
Apr 13, 2010
Messages
2
Location
US
I have an XML file that looks like this:
Code:
<A>
   <B.../>
   <C.../>
   <C.../>
   <C.../>
   <D.../>
   <D.../>
</A>

I am trying to come up with a way to format it like this using XSLT:
Code:
<A>
   <B.../>
   <C.../>
   <D.../>
</A>

I have tried a number of things like using for-each loops that compare the current name to the following-sibling and proceeding with that, however i run into problems when there are multiple, multiple instances. Ex. It works fine if there are multiple instances of ONLY C, but if there are multiples of C AND D, then my code will print out something like this:
Code:
<A>
   <B.../>
   <C...><D...></C></D>
</A>

This is because of the for-each loop going through ALL the elements even after its done what I want.

IMPORTANT:
For this I CANNOT specify C or D specifically. The paths have to be relative axes and generic enough to use for any multiples because these documents have as many as 30-50 multiples and uniquely specifying each one is not what I want.

If anyone can offer up ideas to help me with this it would be much appreciated.

Thanks.
 
What have you so far.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top