Click here to Skip to main content
15,898,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the following XML
XML
  <?xml version="1.0" encoding="UTF-8" ?> 
- <Detail>
	- <Books>
		- <Book_Group>
		  60 
		  <Book_NM>Funda's of Prof Ethics</Book_NM> 
		  <PROMPT_ORD_NO>12</PROMPT_ORD_NO> 
		</Book_Group>
	</Books>
	- <Books>
		- <Book_Group>
		  60 
		  <Book_NM>Decision Making Capabilities</Book_NM> 
		  <Book_ORD_NO>17</Book_ORD_NO> 
		</Book_Group>
	</Books>
	- <Books>
		- <Book_Group>
		  70 
		  <Book_NM>OOPS Concepts</Book_NM> 
		  <Book_ORD_NO>11</Book_ORD_NO> 
		</Book_Group>
	</Books>
	<Books>
	- 	<Book_Group>
		  70 
		  <Book_NM>Power Electronics</Book_NM> 
		  <Book_ORD_NO>13</Book_ORD_NO> 
		</Book_Group>
	</Books>
  </Detail>


Using XSLT I need to have an XML with unique Book_Group as a root element and all the child elements corresponding to that Book_Group as child elements as Shown below:
HTML
<Detail>
	- <Books>
		- <Book_Group>
		  60 
		  <Book_NM>Funda's of Prof Ethics</Book_NM> 
		  <PROMPT_ORD_NO>12</PROMPT_ORD_NO> 
		  <Book_NM>Decision Making Capabilities</Book_NM> 
		  <Book_ORD_NO>17</Book_ORD_NO> 
		</Book_Group>
	</Books>
	- <Books>
		- <Book_Group>
		  70 
		  <Book_NM>OOPS Concepts</Book_NM> 
		  <Book_ORD_NO>11</Book_ORD_NO> 
		  <Book_NM>Power Electronics</Book_NM> 
		  <Book_ORD_NO>13</Book_ORD_NO> 
		</Book_Group>
	</Books>
</Detail>



Kindly provide me with XSLT to achieve the result...Using <xsl:for-each xmlns:xsl="#unknown"> I m not able to do this completely
Posted
Updated 11-Dec-11 20:18pm
v3

1 solution

Check out this example on the w3cschool website.

http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog[^]

If you would change the content of the first title element with that of a Book_Group you'll see that it is going to be very difficult.
XML
<title>60
<Book_NM>Funda's of Prof Ethics</Book_NM><PROMPT_ORD_NO>12</PROMPT_ORD_NO>
</title>

The title shown in the result is "60 Funda's of Prof Ethics12" meaning that grouping is not possible because you won't get an unique value for grouping them.

Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900