<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns="http://hyperrecord.net/hrecord/"
    xmlns:xlink="http://www.w3.org/1999/xlink"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" exclude-result-prefixes="xs"
    xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl" version="2.0"
    >
    <xd:doc scope="stylesheet">
        <xd:desc>
            <xd:p><xd:b>Created on:</xd:b> May 20, 2010</xd:p>
            <xd:p><xd:b>Author:</xd:b> kew</xd:p>
            <xd:p/>
        </xd:desc>
    </xd:doc>
    <xsl:template match="Scheda">
        <xsl:variable name="urn" select="Dati/CAP/LCAP"/>
        <xsl:variable name="output" select="concat(translate($urn, ':', '.'), '.hrc')"/>
        <xsl:result-document encoding="utf-8" method="xml" indent="yes" href="{$output}">
            <?xml-stylesheet type="text/css" href="http://hyperrecord.net/hrecord/hrecord.css" ?>
            <?xxe-relaxng-schema name="-//hyperrecord//hrecordML V0.1//EN" location="http://hyperrecord.net/hrecord/muscap.rng" encoding="UTF-8" ?>
            <?oxygen RNGSchema="http://hyperrecord.net/hrecord/muscap.rng" type="xml"?>
            <record xml:lang="ita" 
                xmlns:ns="http://hyperrecord.net/hrecord/"
                xmlns:xlink="http://www.w3.org/1999/xlink"
                xmlns:legacy="http://hyperrecord.net/hrecord/legacy/"
                xmlns:class="http://collectio.org/classifications/">
                <xsl:attribute name="xlink:href" select="$urn"/>
                <iconography>
                    <xsl:for-each select="Dati/CAT/CATT">
                        <class:objectclass authority="collectio:0002" coverage="undefined">
                            <class:type>
                                <xsl:value-of select="."/>
                            </class:type>
                            <class:form>
                                <xsl:value-of select="//Dati/OGT/OGTD"/>
                            </class:form>
                        </class:objectclass>
                    </xsl:for-each>
                    <denomination>
                        <xsl:value-of select="Dati/SGT/SGTI"/>
                    </denomination>
                </iconography>
                <administration>
                    <!-- hier fehlt end/begin in Simurt: invdd gibt nur 1 feld -->
                    <frame>
                        <begin/>
                        <end/>
                        <owner>
                            <xsl:value-of select="Dati/SINV/SINVP"/>
                        </owner>

                        <administrator>
                            <xsl:value-of select="Dati/SINV/SINVA"/>
                        </administrator>
                        <xsl:for-each select="Dati/SINV/SINVI">
                            <inventary>
                                <name>
                                    <xsl:value-of select="SINVINO"/>
                                </name>
                                <number>
                                    <xsl:value-of select="SINVINU"/>
                                </number>
                                <notes>
                                    <xsl:copy-of select="SINVINT/node()"/>
                                </notes>
                            </inventary>
                        </xsl:for-each>


                    </frame>
                </administration>
                <location>
                    <xsl:for-each select="Dati/LA">
                        <frame>
                            <begin>
                                <date>
                                    <xsl:value-of select="PRD/PRDI"/>
                                </date>
                            </begin>
                            <end>
                                <date>
                                    <xsl:value-of select="PRD/PRDU"/>
                                </date>
                            </end>
                            <class:locationclass authority="collectio:0001" coverage="Rome.Museums">
                                <class:museum>
                                    <xsl:value-of select="PRC/PRCC"/>
                                </class:museum>

                                <class:structure>
                                    <xsl:value-of select="PRC/PRCD"/>
                                </class:structure>

                                <class:substructure>
                                    <xsl:value-of select="PRC/PRCS"/>
                                </class:substructure>
                            </class:locationclass>

                            <notes>
                                <xsl:copy-of select="PRC/PRCNOTE/node()"/>
                            </notes>

                        </frame>
                    </xsl:for-each>
                </location>
                <xsl:if test="not(Dati/DT/DTSN = '')">
                    <creation>
                        <xsl:for-each select="Dati/DT/DTS">
                            <frame>
                                <begin>
                                    <date>
                                        <xsl:value-of select="DTSI"/>
                                    </date>
                                </begin>
                                <end>
                                    <date>
                                        <xsl:value-of select="DTSF"/>
                                    </date>
                                </end>
                                <notes>
                                    <xsl:copy-of select="DTSN/node()"/>
                                </notes>
                            </frame>
                        </xsl:for-each>
                    </creation>
                </xsl:if>
                <techdata>
                    <notes>
                        <xsl:copy-of select="Dati/MT/MTN/node()"/>
                    </notes>
                    <xsl:for-each select="Dati/MIS">
                        <aspect>
                            <xsl:attribute name="name">
                                <xsl:value-of select="MISPA"/>
                            </xsl:attribute>
                            <xsl:variable name="unit" select="MISU"/>
                            <xsl:if test="not(MISAT ='')">
                                <height unit="{$unit}">
                                    <xsl:value-of select="MISAT"/>
                                </height>
                            </xsl:if>
                            <xsl:if test="not(MISLT ='')">
                                <width unit="{$unit}">
                                    <xsl:value-of select="MISLT"/>
                                </width>
                            </xsl:if>
                            <xsl:if test="not(MISPT ='')">
                                <depth unit="{$unit}">
                                    <xsl:value-of select="MISPT"/>
                                </depth>
                            </xsl:if>
                            <xsl:if test="not(MISDT ='')">
                                <diameter unit="{$unit}">
                                    <xsl:value-of select="MISDT"/>
                                </diameter>
                            </xsl:if>
                            <xsl:if test="not(MISST ='')">
                                <thickness unit="{$unit}">
                                    <xsl:value-of select="MISST"/>
                                </thickness>
                            </xsl:if>
                            <xsl:if test="not(MISG ='')">
                                <weight unit="{$unit}">
                                    <xsl:value-of select="MISG"/>
                                </weight>
                            </xsl:if>
                        </aspect>
                    </xsl:for-each>
                    <xsl:for-each select="Dati/MT/MTC">
                        <class:materialclass authority="collectio:0002" coverage="undefined">
                            <class:type>
                                <xsl:value-of select="."/>
                            </class:type>
                        </class:materialclass>
                    </xsl:for-each>
                </techdata>
                <xsl:if test="not(Dati/RTV/RTVN = '' or Dati/RTV/RTVLOC/RTVLOCRE = '' )">
                    <finding>
                        <xsl:for-each select="Dati/RTV">
                            <frame>
                                <begin>
                                    <date>
                                        <xsl:value-of select="RTVD/RTVDI"/>
                                    </date>
                                </begin>
                                <end>
                                    <date>
                                        <xsl:value-of select="RTVD/RTVDF"/>
                                    </date>
                                </end>
                                <class:locationclass authority="collectio:0001" coverage="Italy">
                                    <class:region>
                                        <xsl:value-of select="RTVLOC/RTVLOCRE"/>
                                    </class:region>

                                    <class:city>
                                        <xsl:value-of select="RTVLOC/RTVLOCCI"/>
                                    </class:city>

                                    <class:municipio>
                                        <xsl:value-of select="RTVLOC/RTVLOCMU"/>
                                    </class:municipio>

                                    <class:rione>
                                        <xsl:value-of select="RTVLOC/RTVLOCRI"/>
                                    </class:rione>

                                    <class:place>
                                        <xsl:value-of select="RTVLOC/RTVLOCPO"/>
                                    </class:place>
                                </class:locationclass>

                                <notes>
                                    <xsl:copy-of select="RTVN/node()"/>
                                </notes>
                            </frame>
                        </xsl:for-each>
                    </finding>
                </xsl:if>
                <xsl:if test="not(Dati/RS/RSN = '')">
                    <restoration>
                        <xsl:for-each select="Dati/RS">
                            <frame>
                                <begin>
                                    <date>
                                        <xsl:value-of select="RSD/RSDI"/>
                                    </date>
                                </begin>
                                <end>
                                    <date>
                                        <xsl:value-of select="RSD/RSDF"/>
                                    </date>
                                </end>
                                <notes>
                                    <xsl:copy-of select="RSN/node()"/>
                                </notes>
                            </frame>
                        </xsl:for-each>
                    </restoration>
                </xsl:if>
                <description>
                    <xsl:for-each select="Dati/DES/DESO">
                        <para>
                            <xsl:copy-of select="node()"/>     
                        </para>
                    </xsl:for-each>
                    <!-- waiting for inscription support -->
                </description>
                <bibliography>
                    <xsl:for-each select="Dati/BIB">
                        <entry>
                            <xsl:attribute name="type">
                                <xsl:value-of select="BIBX"/>
                            </xsl:attribute>
                            <xsl:value-of select="BIBNOTE"/>
                        </entry>
                    </xsl:for-each>
                </bibliography>
                <editing>
                    <xsl:for-each select="Dati/CM">
                        <editorship>
                        <date><xsl:value-of select="CMPN"/></date>
                        <name><xsl:value-of select="CMPD"/></name>
                        <notes><xsl:value-of select="CMN"/></notes>
                            </editorship>
                    </xsl:for-each>
                </editing>
                <legacy:data>
                    <xsl:value-of select="Dati/AN/OSS"></xsl:value-of>
                </legacy:data>
            </record>
        </xsl:result-document>
    </xsl:template>
</xsl:stylesheet>

