我需要为<Project>
,<Skill>
,<training>
,<duration>
,<ProjectTitle>
,<Description>
的每个重复元素创建唯一记录,<Tools>
和<Tools_Rating>
。
我尝试使用XSLT中的已知选项,但我得不到正确的结果。能否帮我为下面的输入XML生成XSLT。
输入Xml:
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
<Project>def</Project>
<Skill>unix</Skill>
<Project>efg</Project>
<Skill>xml</Skill>
<Project>pqr</Project>
<Skill>sql</Skill>
<Project>xyz</Project>
<Skill>Analytics</Skill>
<Training>Unix</Training>
<Duration>30 minutes</Duration>
<Training>Xml</Training>
<Duration>50 minutes</Duration>
<Training>Java</Training>
<Duration>45 minutes</Duration>
<Training>sql</Training>
<Duration>15 minutes</Duration>
<Training>Analytics</Training>
<Duration>30 minutes</Duration>
<ProjectTitle>abc</ProjectTitle>
<Description>adafdahf</Description>
<ProjectTitle>def</ProjectTitle>
<Description>jhiuhghs</Description>
<ProjectTitle>efg</ProjectTitle>
<Description>hweuiywu</Description>
<ProjectTitle>xyz</ProjectTitle>
<Description>jgdghoh</Description>
<Tools>bcd</Tools>
<Tools_Rating>4<Tools_Rating>
<Tools>ght</Tools>
<Tools_Rating>3<Tools_Rating>
<Tools>fed</Tools>
<Tools_Rating>2<Tools_Rating>
<Tools>pqr</Tools>
<Tools_Rating>4<Tools_Rating>
</Record>
</root>
输出Xml:
<root>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>abc</Project>
<Skill>java</Skill>
</Record>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>def</Project>
<Skill>unix</Skill>
<Training>Unix</Training>
<Duration>30 minutes</Duration>
<ProjectTitle>abc</ProjectTitle>
<Description>adafdahf</Description>
<Tools>bcd</Tools>
<Tools_Rating>4<Tools_Rating>
</Record>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>efg</Project>
<Skill>xml</Skill>
<Training>Xml</Training>
<Duration>50 minutes</Duration>
<ProjectTitle>def</ProjectTitle>
<Description>jhiuhghs</Description>
<Tools>ght</Tools>
<Tools_Rating>3<Tools_Rating>
</Record>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>pqr</Project>
<Skill>sql</Skill>
<Training>Java</Training>
<Duration>45 minutes</Duration>
<ProjectTitle>efg</ProjectTitle>
<Description>hweuiywu</Description>
<Tools>fed</Tools>
<Tools_Rating>2<Tools_Rating>
</Record>
<Record>
<Emp_ID>288237</Emp_ID>
<Emp_Name>John</Emp_Name>
<Country>US</Country>
<Manager>Wills</Manager>
<Join_Date>5/12/2014</Join_Date>
<Experience>9 years</Experience>
<Project>xyz</Project>
<Skill>Analytics</Skill>
<Training>sql</Training>
<Duration>15 minutes</Duration>
<ProjectTitle>xyz</ProjectTitle>
<Description>jgdghoh</Description>
<Tools>pqr</Tools>
<Tools_Rating>4<Tools_Rating>
</Record>
</root>
使用过XSLT:但无法获取输出xml。
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<root>
<xsl:for-each select="root/Record/Project">
<Record>
<xsl:copy-of select="../*[not(self::Project or self::Skill or self::Training or self::Duration or self::ProjectTitle or self::Decription or self::Tools or self::Tools_Rating)]"/>
<xsl:copy-of select=". | following-sibling::Skill[1] | following-sibling::Duration[1] | following-sibling::Decription[1] | following-sibling::Tools_Rating[1]"/>
</Record>
</xsl:for-each>
</root>
这些问题和答案之间没有连接。我希望这些设置的问题值能够在一行中显示第一个记录,依此类推。
示例:
<record>
<qid>
<First set of first question>
<First set of firstanswer>
<second set of first question>
<second set of first answer>
.....
.....
....
</Record>
类似于更多的qustion到达意味着,我需要为所有集合的第一个问题和第二个记录创建记录到所有集合的第二个问题。请帮助解决这个问题,我也是这个xslt的新手。
先谢谢