Я очень плохо знаком с xsl и на этапе обучения мне нужна помощь по преобразованию XML в другую структуру XML, так как я пробовал много способов, но не смог найти решение, которое я ищу
Вот мой ввод xml
<Output>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType1</TYPENAME>
<FROMSTATE>State3</FROMSTATE>
<TOSTATE></TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType1</TYPENAME>
<FROMSTATE>State1</FROMSTATE>
<TOSTATE>State2;State3</TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType2</TYPENAME>
<FROMSTATE>State3</FROMSTATE>
<TOSTATE></TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType2</TYPENAME>
<FROMSTATE>State1</FROMSTATE>
<TOSTATE>State2;State3</TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType3</TYPENAME>
<FROMSTATE>State3</FROMSTATE>
<TOSTATE></TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
<refcur>
<OVERALLSTATUS>TRUE</OVERALLSTATUS>
<MODULE>ABC</MODULE>
<TYPENAME>ABCType3</TYPENAME>
<FROMSTATE>State1</FROMSTATE>
<TOSTATE>State2;State3</TOSTATE>
<EXCEPTION></EXCEPTION>
</refcur>
</Output>
Вот формат, который мне нужен
<Output>
<refcur>
<Module>ABC</Module>
<Transition>
<TypeName>ABCType1</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
</Transition>
<Transition>
<TypeName>ABCType2</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
</Transition>
<Transition>
<TypeName>ABCType3</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
<Transition>
</refcur>
</Output>
Это мой xslt
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">
<xsl:output method="xml" indent="yes"/>
<xsl:key name="groups" match="/Output/refcur" use="TYPENAME" />
<xsl:template match="/Output">
<xsl:apply-templates select="refcur[generate-id() = generate-id(key('groups', TYPENAME)[1])]"/>
</xsl:template>
<xsl:template match="refcur">
<Output>
<refcur>
<Module>
<xsl:value-of select="MODULE"/>
</Module>
<Transition>
<TypeName>
<xsl:value-of select="TYPENAME"/></TypeName>
<xsl:for-each select="key('groups', TYPENAME)">
<Location>
<FromLocation>
<xsl:value-of select="FROMSTATE"/>
</FromLocation>
<ToLocation>
<xsl:value-of select="TOSTATE"/>
</ToLocation>
<Exception>
<xsl:value-of select="EXCEPTION"/>
</Exception>
</Location>
</xsl:for-each>
</Transition>
</refcur>
</Output>
</xsl:template>
</xsl:stylesheet>
Но это преобразовать в приведенный ниже формат
<Output>
<refcur>
<Module>ABC</Module>
<Transition>
<TyeName>ABCType1</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
</Transition>
</refcur>
</Output>
<Output>
<refcur>
<Module>ABC</Module>
<Transition>
<TyeName>ABCType2</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
</Transition>
</refcur>
</Output>
<Output>
<refcur>
<Module>ABC</Module>
<Transition>
<TyeName>ABCType3</TypeName>
<Location>
<FromLocation>State3</FromLocation>
<ToLocation></ToLocation>
<Exception></Exception>
</Location>
<Location>
<FromLocation>State1</FromLocation>
<ToLocation>State2;State3</ToLocation>
<Exception></Exception>
</Location>
</Transition>
</refcur>
</Output>
Может кто-нибудь помочь мне исправить xsl?
Вот код C# для генерации вывода xml
static void Main(string[] args)
{
string baseName = @"C:\temp\XMLTOXML\XMLTOXML";
XslCompiledTransform myXslTransform = new XslCompiledTransform();
myXslTransform.Load(baseName + "\\transform.xslt");
myXslTransform.Transform(baseName + "\\InputXml.xml", baseName + "\\OutputXml.xml");
}