<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
    exclude-result-prefixes="xd"
    version="1.0">
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> Oct 17, 2010</xd:p>
            <xd:p><xd:b>Author:</xd:b> db@dbalzer.net</xd:p>
        </xd:desc>
    </xd:doc>
    <xsl:template match="/">
        <html>
            <title>Transformed view of test record in EN 15907 XML encoding</title>
            <style type="text/css">
                p { font-family: sans-serif; font-size:11pt; padding:0; 
                    margin-bottom:2pt; margin-top:0 }
                p.labelr { text-align:right }
                code { font-family: sans-serif; font-weight:bold; color:#044800 }
                td { vertical-align:top }
                div.topbar { background-color:#D9D9D9; padding:3pt }
                div.work { background-color:#F1F1D9; padding:3pt }
            </style>
        </html>
        <xsl:apply-templates />
    </xsl:template>
    <xsl:template match="ns1:CinematographicWork" xmlns:ns1="http://filmstandards.org/schemas/EN15907-d1">
        <div class="topbar">
            <p>Transformed view of test record in EN 15907 XML encoding</p>
        </div>
        <div class="work">
            <p><strong>Cinematographic Work</strong></p>
            <table>
                <tr>
                    <td><p class="labelr">Record:</p></td>
                    <td><p><code><xsl:value-of select="ns1:Identifier" /></code>
                from: 
                <code><xsl:value-of select="ns1:RecordSource/ns1:SourceName" /></code>
                    </p></td>
                </tr>
                <tr>
                    <td><p class="labelr">Identifying Title:</p></td>
                    <td><p>                    
                <code><xsl:apply-templates select="ns1:IdentifyingTitle"/></code>
                    </p></td>
                </tr>
                <tr>
                    <td><p class="labelr">Country of Reference:</p></td>
                    <td><p><xsl:apply-templates select="ns1:CountryOfReference"/>
                    </p></td>
                </tr>
                <tr>
                    <td><p class="labelr">Year of Reference:</p></td>
                    <td><p>                    
                        <code><xsl:value-of select="ns1:YearOfReference"/></code>
                    </p></td>
                </tr>
                <tr>
                    <td><p class="labelr">Director(s):</p></td>
                    <td><p><xsl:call-template name="directors" /></p></td>
                </tr>
                <tr>
                    <td><p class="labelr">Production Company/ies:</p></td>
                    <td><p><xsl:call-template name="production" /></p></td>
                </tr>
            </table>
        </div>
    </xsl:template>
    
    <xsl:template name="directors" xmlns:ns1="http://filmstandards.org/schemas/EN15907-d1">
        <xsl:for-each select="ns1:AgentRelationship[ns1:Activity='Director']">
            <xsl:if test="position()>1"> ; </xsl:if>
            <code><xsl:value-of select="ns1:AgentName" /></code>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template name="production" xmlns:ns1="http://filmstandards.org/schemas/EN15907-d1">
        <xsl:for-each select="ns1:AgentRelationship[ns1:Activity='Production Company']">
            <xsl:if test="position()>1"> ; </xsl:if>
            <code><xsl:value-of select="ns1:AgentName" /></code>
        </xsl:for-each>
    </xsl:template>

    <xsl:template match="ns1:IdentifyingTitle" xmlns:ns1="http://filmstandards.org/schemas/EN15907-d1">
        <xsl:if test="substring-before(.,'_') ">
            <i><xsl:value-of select="substring-before(.,'_')" /></i>
            <xsl:value-of select="substring-after(.,'_')" />
        </xsl:if>
        <xsl:if test="not(substring-before(.,'_')) ">
            <xsl:value-of select="." />
        </xsl:if>
    </xsl:template>
    
    <xsl:template match="ns1:CountryOfReference" xmlns:ns1="http://filmstandards.org/schemas/EN15907-d1">
        <xsl:for-each select="ns1:Country">
            <xsl:if test="position()>1"> / </xsl:if>
            <code><xsl:value-of select="ns1:RegionCode" /></code>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>