使用XSLT对XML进行分组 [英] Grouping XML using XSLT

查看:176
本文介绍了使用XSLT对XML进行分组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下XML

I have the following 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>



使用XSLT,我需要有一个XML,其唯一的Book_Group作为根元素,而与该Book_Group对应的所有子元素作为子元素,如下所示:



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:

<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>




请为我提供XSLT以实现结果...使用< xsl:for-each xmlns:xsl =#unknown">我无法完全做到这一点.




Kindly provide me with XSLT to achieve the result...Using <xsl:for-each xmlns:xsl="#unknown"> I m not able to do this completely

推荐答案

在w3cschool网站上查看此示例.

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

如果您将第一个title元素的内容更改为Book_Group的内容,将会发现这将非常困难.
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.
<title>60
<Book_NM>Funda's of Prof Ethics</Book_NM><PROMPT_ORD_NO>12</PROMPT_ORD_NO>
</title>


结果中显示的标题是" Ethics12教授的60个Funda's ",这意味着无法进行分组,因为您将无法获得唯一的分组价值.

祝你好运!


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!


这篇关于使用XSLT对XML进行分组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆