Мой оригинальный XML
<?xml version="1.0" encoding="UTF-8"?>
<testing>
<MajorEvent>
<Originator>xxxx/Originator>
<Version>V1</Version>
</MajorEvent>
<Event Date="26-03-11_04:00:00:00" >
<AudioName>AT1</AudioName>
<ItemName>F7000533</ItemName>
<Lang>
<Languages>Language1|Language2</Languages>
</Lang>
<EventID>4333</EventID>
</Event>
</testing>
Я хочу производить события в зависимости от языков и имени пользователя. Например, в этом есть 3 события, поэтому выход будет
<?xml version="1.0" encoding="UTF-8"?>
<testing>
<MajorEvent>
<Originator>xxxx/Originator>
<Version>V1</Version>
</MajorEvent>
<Event Date="26-03-11_04:00:00:00" >
<AudioName>AT1</AudioName>
<ItemName>F7000533</ItemName>
<Lang>
<Languages>Language1|Language2</Languages>
</Lang>
<EventID>4333</EventID>
</Event>
<Event Date="26-03-11_04:00:00:00">
<AudioName>AT1</AudioName>
<ItemName>F7000533-AT1</ItemName>
<EventID>4333</EventID>
</Event>
<Event Date="26-03-11_04:00:00:00" >
<AudioName>AT1</AudioName>
<ItemName>F7000533-Language1</ItemName>
<Lang>
<Languages>Language1|Language2</Languages>
</Lang>
<EventID>4333</EventID>
</Event>
<Event Date="26-03-11_04:00:00:00" >
<AudioName>AT1</AudioName>
<ItemName>F7000533-Language2</ItemName>
<Lang>
<Languages>Language1|Language2</Languages>
</Lang>
<EventID>4333</EventID>
</Event>
</testing>
Я написал xslt.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:exsl="http://exslt.org/common"
extension-element-prefixes="exsl" >
<xsl:output method="xml" indent="yes" encoding="UTF-8" />
<xsl:template match="/testing">
<xsl:element name="testing">
<xsl:apply-templates select="MajorEvent" />
<xsl:apply-templates select="Event" />
</xsl:element>
</xsl:template>
<xsl:template match="MajorEvent">
<xsl:element name="MajorEvent">
<xsl:copy-of select="Originator" />
<xsl:copy-of select="Version" />
</xsl:element>
</xsl:template>
<xsl:template match="Event">
<xsl:element name="Event">
<xsl:attribute name="Date">
<xsl:value-of select="@Date" />
</xsl:attribute>
<xsl:copy-of select="AudioName" />
<xsl:copy-of select="ItemName" />
<xsl:copy-of select="EventID" />
</xsl:element>
<xsl:for-each select="AudioName">
<xsl:element name="Event">
<xsl:attribute name="Date">
<xsl:value-of select="../@Date" />
</xsl:attribute>
<xsl:variable name="item_name" select="../ItemName" />
<xsl:variable name="audio" select="../AudioName" />
<xsl:copy-of select="../AudioName" />
<xsl:element name="ItemName">
<xsl:value-of select="concat($item_name,'-',$audio)" />
</xsl:element>
<xsl:copy-of select="../EventID" />
</xsl:element>
</xsl:for-each>
<xsl:variable name="SplitLanguage">
<xsl:call-template name="SplitLanguage">
<xsl:with-param name="Languages" select="Lang/Languages" />
</xsl:call-template>
</xsl:variable>
<xsl:for-each select="exsl:node-set($SplitLanguage)/*">
<xsl:element name="Event">
<xsl:attribute name="Date">
<xsl:value-of select="Date" />
</xsl:attribute>
<xsl:variable name="item_name" select="../ItemName" />
<xsl:variable name="lang" select="." />
<xsl:element name="ItemName">
<xsl:value-of select="concat($item_name,'-',$lang)" />
</xsl:element>
</xsl:element>
</xsl:for-each>
</xsl:template>
<xsl:template name="SplitLanguage">
<xsl:param name="Languages" select="." />
<xsl:if test="string-length($Languages) >0">
<item>
<xsl:value-of select="substring-before(concat($Languages, ','), ',')" />
</item>
<xsl:call-template name="SplitLanguage">
<xsl:with-param name="Languages"
select="substring-after($Languages, ',')" />
</xsl:call-template>
</xsl:if>
</xsl:template>
</xsl:stylesheet>
Я получаю этот результат
<?xml version="1.0" encoding="UTF-8"?>
<testing>
<MajorEvent>
<Originator>xxxx</Originator>
<Version>V1</Version>
</MajorEvent>
<Event Date="26-03-11_04:00:00:00">
<AudioName>AT1</AudioName>
<ItemName>F7000533</ItemName>
<EventID>4333</EventID>
</Event>
<Event Date="26-03-11_04:00:00:00">
<AudioName>AT1</AudioName>
<ItemName>F7000533-AT1</ItemName>
<EventID>4333</EventID>
</Event>
<Event Date="">
<ItemName>-Language1</ItemName>
</Event>
<Event Date="">
<ItemName>-Language2</ItemName>
</Event>
</testing>
Кто-нибудь знает, что я здесь делаю неправильно?