I have to use XSL 1.0 to solve the following problem. I am a beginner to XSL, so please bear with me if it is trivial.
I use a file called transform.xsl to transform left.xml to right.xml. I will show the files, then explain the logic.
Here is left.xml:
<?xml version="1.0" ?>
<parties>
<party>
<id>123</id>
<pending>456,789,234</pending>
<name>NYC Film Festival</name>
</party>
<party>
<id>345</id>
<pending>234</pending>
<name>Montreal Film Festival</name>
</party>
<party>
<id>345</id>
<pending />
<name>LA Film Festival</name>
</party>
</parties>
Here is right.xml
<?xml version="1.0" ?>
<parties>
<Aparty name="NYC Film Festival" id="456"/>
<Aparty name="NYC Film Festival" id="789"/>
<Aparty name="NYC Film Festival" id="234"/>
<Aparty name="Montreal Film Festival" id=234/>
<Aparty name="LA Film festival" id=345>
</parties>
The idea is as follows. Consider the left.xml. If the pending node inside party is empty, use id for right.xml. Otherwise, split the content inside the pending tag and insert a node for each. The splitting is throwing me off, especially since I have to use XSL 1.0
Can someone please help?
My current transform.xsl looks like this
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:element name="parties">
<xsl:apply-templates select="parties/party"/>
</xsl:element>
</xsl:template>
<xsl:template match="parties/party">
<xsl:choose>
<xsl:when test="boolean(pending) and string(pending) != ''">
<xsl:element name="Aparty">
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="pending"/>
</xsl:attribute>
</xsl:element>
</xsl:when>
<xsl:otherwise>
<xsl:element name="Aparty">
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
<xsl:attribute name="id">
<xsl:value-of select="id"/>
</xsl:attribute>
</xsl:element>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>