<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/02/xpath-functions"
    xmlns:idea="http://www.ideadistributors.com/idea/xsl" exclude-result-prefixes="#all">
    <xsl:include href="idea-functions.xsl"/>
    <xsl:include href="mapping/rhapsody-mapping.xsl"/>
    <xsl:template match="album">
        <xsl:if test="string-length(upc) >= 12">
            <xsl:variable name="upc" select="upc"/>
            <albums xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                xsi:noNamespaceSchemaLocation="listenDD.xsd">
                        <xsl:attribute name="partnerID" select="vendor-id"/>
                <album>
                    <id>
                        <xsl:value-of select="$upc"/>
                    </id>
                    <upc>
                        <xsl:value-of select="$upc"/>
                    </upc>
                    <name>
                        <xsl:value-of select="title"/>
                    </name>
                    <releaseDate>
                        <xsl:value-of select="release-date"/>
                    </releaseDate>
                    <label>
                        <xsl:value-of select="label"/>
                    </label>
                    <xsl:for-each select="genre">
                        <style>
                            <xsl:value-of select="idea:mapGenre(node())"/>
                        </style>
                    </xsl:for-each>
                    <xsl:choose>
                        <xsl:when test="compare(is-explicit, 'explicit') = 0">
                            <albumType>Parental Advisory</albumType>
                        </xsl:when>
                    </xsl:choose>
                    <artist>
                        <name>
                            <xsl:value-of select="display-artist"/>
                        </name>
                        <role>Primary</role>
                    </artist>
                    <xsl:for-each select="volume">
                        <xsl:variable name="volume" select="sequence"/>
                        <xsl:for-each select="track">
                            <track>
                                <id>
                                    <xsl:value-of select="replace(isrc, '-', '')"/>
                                </id>
                                <name>
                                    <xsl:value-of select="title"/>
                                </name>
                                <isrc>
                                    <xsl:value-of select="isrc"/>
                                </isrc>
                                <discNumber>
                                    <xsl:value-of select="$volume"/>
                                </discNumber>
                                <sequence>
                                    <xsl:value-of select="sequence"/>
                                </sequence>
                                <length>
                                    PT<xsl:value-of select="audio-duration"/>S
                                </length>
                                <xsl:if test="exists(pline)">
                                    <pLine>
                                        <xsl:value-of select="pline"/>
                                    </pLine>
                                </xsl:if>
                                <xsl:if test="exists(cline)">
                                    <cLine>
                                        <xsl:value-of select="cline"/>
                                    </cLine>
                                </xsl:if>
                                <xsl:choose>
                                    <xsl:when test="//track[@sell-unbundled = 'no']">
                                        <saleRestriction>Entire Album Only</saleRestriction>
                                    </xsl:when>
                                    <xsl:otherwise> </xsl:otherwise>
                                </xsl:choose>
                                <artist>
                                    <name>
                                        <xsl:value-of select="display-artist"/>
                                    </name>
                                    <role>Primary</role>
                                </artist>
                                <xsl:if test="normalize-space(composer)" >
                                  <artist>
                                      <name>
                                          <xsl:value-of select="composer"/>
                                      </name>
                                      <role>Composer</role>
                                  </artist>
                                </xsl:if>
                                <right type="labelStream">Y</right>
                                <right type="labelBurn">Y</right>
                                <right type="labelDownload">Y</right>
                                <right type="publisherBurn">Y</right>
                                <right type="publisherDownload">Y</right>
                                <mediaFile>
                                    <bitrate>256</bitrate>
                                    <format>AAC</format>
                                    <fileName>
                                        <xsl:value-of select="audio-filename"/>
                                    </fileName>
                                </mediaFile>
                            </track>
                        </xsl:for-each>
                    </xsl:for-each>
                    <image>
                        <format>JPEG</format>
                        <width>600</width>
                        <height>600</height>
                        <fileName>
                            <xsl:value-of select="image-filename"/>
                        </fileName>
                    </image>
                </album>
            </albums>
        </xsl:if>
    </xsl:template>
</xsl:stylesheet>
