<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:variable name="success" select="/aksPeopleAPI/resultInfo/success"></xsl:variable>

<table border="1" width="350" cellspacing="0" cellpadding="0" bgcolor="#828282" style="font-size:9pt">
<tr><td>
<table border="0" width="350" cellspacing="1" cellpadding="1" bgcolor="#FFFFFF" style="font-size:9pt">
<xsl:if test="$success = 'false'">
<tr><td><xsl:value-of select='/aksPeopleAPI/resultInfo/message'/></td></tr>
</xsl:if>
<xsl:if test="$success = 'true'">
<xsl:apply-templates select="/aksPeopleAPI/resultInfo/resultSet/list/document/통합인명메타"/>
</xsl:if>
</table>
</td></tr>
</table>

</xsl:template>

<xsl:template match="통합인명메타">
<tr>
<td class="first"><span>UCI</span></td><td><a id="uci"><xsl:value-of select="./@UCI"/></a></td>
</tr>
<xsl:apply-templates select="인명정보/인명"/>

<!-- 생졸년 -->
<xsl:call-template name="생졸년">
<xsl:with-param name="생년" select="생몰년정보/생년"/>
<xsl:with-param name="몰년" select="생몰년정보/몰년"/>
</xsl:call-template>

<xsl:apply-templates select="/DOCUMENT/인물사전/시대"/>

<xsl:if test="./본관">
<tr>
<td class="first"><span>본관</span></td>
<td>
<span class="place">
<xsl:choose>
<xsl:when test="본관/@id='200'"><xsl:value-of select="./본관"/></xsl:when>
<xsl:otherwise>
<a class="place">
<xsl:attribute name="href">/front/dirSer/lst/lstView.aks?originnameId=<xsl:value-of select="본관/@id"/>&amp;familynameId=<xsl:value-of select="인명[@유형='성']/@id"/></xsl:attribute>
<xsl:value-of select="./본관"/>
</a>
</xsl:otherwise>
</xsl:choose>
</span>
</td>
</tr>
</xsl:if>
<xsl:if test="./분류정보">
<tr>
<td class="first"><span>활동분야</span></td>
<td>
<xsl:apply-templates select="./분류정보/분류"/>
</td>
</tr>
</xsl:if>
</xsl:template>

<xsl:template match="인명정보/인명">
<xsl:choose>
<xsl:when test="(./@유형) and (./@표시='대표')"></xsl:when>
<xsl:when test="(./@유형) and (./@유형='성명')"></xsl:when>
<xsl:when test="(./@유형) and (./@유형='성')"></xsl:when>
<xsl:when test="string-length(.)=0"></xsl:when>
<xsl:otherwise>
<tr>
<td class="first"><span><xsl:value-of select="@유형"/></span></td>
<td><span class="ppl"><xsl:value-of select="./@한글음"/><xsl:if test="not(string-length(.) = 0)">(<xsl:apply-templates/>)</xsl:if></span> </td>
</tr>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="분류정보/분류">
<xsl:if test="not(string-length(.)=0)">
<xsl:if test="not(position() = '1')"> &gt; </xsl:if><xsl:value-of select="."/>
</xsl:if>
</xsl:template>

<xsl:template match="본관">
<xsl:if test="not(string-length(@유형) = 0)">
<span class="subTitle"><xsl:value-of select="@유형"/></span>
</xsl:if>
<xsl:variable name="linkId" select="./@id" />
<xsl:if test="not(string-length($linkId) = 0)">
<a href="#" class="lst">
<xsl:attribute name="href">/front/dirSer/lst/lstView.aks?lstId=<xsl:value-of select="$linkId"/></xsl:attribute><xsl:apply-templates/>
</a>
</xsl:if>
<xsl:if test="string-length($linkId) = 0">
<span class="lst"><xsl:apply-templates/></span>
</xsl:if>
</xsl:template>

<xsl:template match="시대">
<tr>
<td class="first"><span>시대</span></td>
<td><span class="ppl"><xsl:value-of select="./@명"/></span> </td>
</tr>
</xsl:template>

<xsl:template name="생졸년">
<xsl:param name="생년"/>
<xsl:param name="몰년"/>

<tr>
<td class="first"><span>생몰년</span></td>
<td><xsl:call-template name="YEAR2INT"><xsl:with-param name="YEAR" select="$생년/연도"/></xsl:call-template><xsl:apply-templates select="$생년/왕대"/> ~ <xsl:call-template name="YEAR2INT"><xsl:with-param name="YEAR" select="$몰년/연도"/></xsl:call-template><xsl:apply-templates select="$몰년/왕대"/></td>
</tr>
</xsl:template>

<xsl:template match="왕대">
<xsl:if test="not(string-length(./text()) = 0)">(<xsl:value-of select="."/>)</xsl:if>
</xsl:template>

<xsl:template name="YEAR2INT">
<xsl:param name="YEAR"/>

<xsl:choose>
<xsl:when test="($YEAR/text() = '9999') or (normalize-space($YEAR/text()) = '')">?</xsl:when>
<xsl:otherwise><xsl:value-of select="$YEAR"/></xsl:otherwise>
</xsl:choose>
</xsl:template>

<xsl:template match="br">
<br></br>
</xsl:template>

<xsl:template match="BR">
<br></br>
</xsl:template>

<xsl:template match="text()">
<xsl:call-template name="pbr" />
</xsl:template>

<xsl:template name="pbr">
<xsl:param name="text" select="."/>
<xsl:choose>
<xsl:when test="contains($text, '.&#10;')">
<xsl:value-of select="substring-before($text, '&#10;')"/>
<br/><br/>
<xsl:call-template name="pbr">
<xsl:with-param name="text" select="substring-after($text, '&#10;')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$text"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:variable name="FontBaseURL">http://www.koreanhistory.or.kr/newchar/fontimg/</xsl:variable>
<xsl:variable name="FontBaseSize">24</xsl:variable> <!-- 16, 24, 48 -->
<xsl:variable name="FontImgWidth">16</xsl:variable>
<xsl:variable name="FontImgHeight">16</xsl:variable>

<xsl:template match="imghj">
<xsl:element name="img">
<xsl:attribute name="src"><xsl:value-of select="$FontBaseURL"/><xsl:value-of select="@href"/>_<xsl:value-of select="$FontBaseSize"/>.GIF</xsl:attribute>
<xsl:attribute name="border">0</xsl:attribute>
<xsl:attribute name="valign">bottom</xsl:attribute>
<xsl:attribute name="height">16px;</xsl:attribute>
</xsl:element>
</xsl:template>

</xsl:stylesheet>