<?xml version="1.0" encoding="utf-8" ?>
<?xml-stylesheet href="/parts/xsltdoc.xsl" type="text/xsl" media="screen" ?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY classnames "concat('|',@class,'|')">
<!ENTITY localnames "concat('|',local-name(),'|')">
<!ENTITY articleclass "'|article|entry|blogentry|entryItem|'">
<!ENTITY dcwho "|creator|publisher|contributor|">
<!ENTITY dcboth "coverage|description|rights|">
<!ENTITY dcclass "'&dcwho;&dcboth;date|format|identifier|title|author|'">
<!ENTITY dcrel "'|&dcboth;relation|source|subject|'">
<!ENTITY dctrel "'|references|isPartOf|hasPart|'">
<!ENTITY coreblockelt "|p|div|dd|li|">
<!ENTITY core-and-tbl "&coreblockelt;table|">
<!ENTITY listelt "ul|ol|dl|">
<!ENTITY headings "h1|h2|h3|h4|h5|h6|">
<!ENTITY blockelt "'&coreblockelt;&listelt;&headings;address|blockquote|td|th|'">
<!ENTITY hblockelt "h:p|h:div|h:dd|h:ul|h:ol|h:li|h:dl|h:h1|h:h2|h:h3|h:h4|h:h5|h:h6|h:address|h:blockquote|h:table">
<!ENTITY inlineelt "'|a|em|strong|cite|abbr|var|span|dt|caption'">
<!ENTITY hinlineelt "h:a|h:em|h:strong|h:dfn|h:cite|h:abbr|h:var|h:span|h:dt">
<!ENTITY rdfns "http://www.w3.org/1999/02/22-rdf-syntax-ns#">
<!ENTITY sitemap "http://purl.org/net/ns/sitemap#">
]>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:rdf="&rdfns;"
  xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
  xmlns:owl="http://www.w3.org/2002/07/owl#"
  xmlns:h="http://www.w3.org/1999/xhtml"
  xmlns:dct="http://purl.org/dc/terms/"
  xmlns:dcterms="http://purl.org/dc/terms/"
  xmlns:dc="http://purl.org/dc/elements/1.1/"
  xmlns:foaf="http://xmlns.com/foaf/0.1/"
  xmlns:wn="http://xmlns.com/wordnet/1.6/"
  xmlns:xhv="http://www.w3.org/1999/xhtml/vocab#"
  xmlns:wm="http://purl.org/net/ns/wordmap#"
  xmlns:sitemap="&sitemap;"
  xmlns:doas="http://purl.org/net/ns/doas#"
  exclude-result-prefixes="h doas"
>

 <xsl:template name="_doas_description">
  <rdf:RDF xmlns="http://purl.org/net/ns/doas#">
   <rdf:Description rdf:about="">
    <title>Metadata extractor stylesheet</title>
    <description>This stylesheet is designed to extract metadata from XHTML, especially with GRDDL. Can be used with http://purl.org/net/ns/metaprof as a profile URI. *KeywordSet test version</description>
    <description xml:lang="ja">XHTMLの要素型とclass, rel属性値を利用し、GRDDLによってメタデータRDF/XMLを抽出するためのスタイルシートです。head要素のprofile属性にhttp://purl.org/net/ns/metaprofを記述するだけで利用できます。</description>
    <author rdf:parthType="Resource">
     <name>Masahide Kanzaki</name>
     <homepage rdf:resource="http://www.kanzaki.com/"/>
    </author>
    <created>2004-03-03</created>
    <release rdf:parthType="Resource">
     <revision>2.5.2</revision>
     <created>2009-03-19</created>
    </release>
    <rights>(c) 2004-2009 by the author, copyleft under LGPL</rights>
    <license rdf:resource="http://creativecommons.org/licenses/LGPL/2.1/"/>
   </rdf:Description>
  </rdf:RDF>
 </xsl:template>

 <xsl:output method="xml" media-type="application/xml" indent="yes"/>
 <xsl:param name="xmlfile"/>
 <!-- basic variables of XML NS uris and base uri -->
 <xsl:variable name="schemas" select="/h:html/h:head/h:link[starts-with(@rel,'schema.')]"/>
 <xsl:variable name="myns" select="document('')/xsl:stylesheet/namespace::*"/>
 <xsl:variable name="baseuri">
  <xsl:choose>
   <xsl:when test="/h:html/h:head/h:base"><xsl:value-of select="/h:html/h:head/h:base/@href"/></xsl:when>
   <xsl:when test="/h:html/h:body/h:address//h:cite[@id='orguri']"><xsl:value-of select="/h:html/h:body/h:address//h:cite[@id='orguri']"/></xsl:when>
   <xsl:when test="$xmlfile"><xsl:value-of select="$xmlfile"/></xsl:when>
  </xsl:choose>
 </xsl:variable>
 <!--
 <xsl:template match="/">
  <xsl:apply-templates select="h:html"/>
 </xsl:template>
-->
 <xsl:template match="/h:html">
  <!--** Main XHTML document handler template. This stylesheet can extract metadata form predefined class, rel attributes and schema prefixed class, rel attributes.-->
  <rdf:RDF>
   <xsl:comment>This RDF is generated from XHTML via GRDDL</xsl:comment>
   <foaf:Document rdf:about="">
    <xsl:if test="$baseuri != ''">
     <xsl:attribute name="xml:base"><xsl:value-of select="$baseuri"/></xsl:attribute>
    </xsl:if>
    <xsl:apply-templates select="h:head"/>
    <xsl:apply-templates select="h:body"/>
   </foaf:Document>
  </rdf:RDF>
 </xsl:template>


 <!--===================== metadata from XHTML head element ==================-->
 
 <xsl:template match="h:head">
  <!--** Get basic document metadata from <title>, <meta> and <link> elements -->
  <dc:title><xsl:value-of select="normalize-space(h:title)"/></dc:title>
  <xsl:apply-templates select="h:meta"/>
  <xsl:apply-templates select="h:link"/>
  <!--@ setup author's metadata (ページ作者に関するメタデータを取得) -->
  <xsl:call-template name="who"/>
 </xsl:template>

 <xsl:template match="h:meta">
  <!--** Meta elements with a predefined name (meta要素の処理). Steps: -->
  <xsl:choose>

   <!--@ case: @name is schema prefixed, resolve ns, and generate a property ('.'を含む名前のときは名前空間を解決してからプロパティを生成) -->
   <xsl:when test="contains(@name,'.')">
    <xsl:variable name="ns">
     <xsl:call-template name="find-ns">
      <xsl:with-param name="pfx" select="substring-before(@name,'.')"/>
     </xsl:call-template>
    </xsl:variable>
    <xsl:element name="{translate(@name,'.',':')}" namespace="{$ns}">
     <xsl:value-of select="@content"/>
    </xsl:element>
   </xsl:when>

   <!--@ case: @name='description', dc:description (descriptionからはdc:descriptionを) -->
   <xsl:when test="@name='description'">
    <dc:description><xsl:value-of select="@content"/></dc:description>
   </xsl:when>

   <!--@ case: @name='keywords', generates property 'wm:keywordSet' and object 'wm:WordSet', then call template 'proc-keyword' to generate appropriate 'wm:associatedWord'. (keywordsについてはプロパティ'wm:keywordSet'と目的語ノード'wm:WordSet'を生成してからテンプレート'proc-keyword'を呼び出す) -->
   <xsl:when test="@name='keywords'">
    <wm:keywordSet>
     <wm:WordSet rdf:about="#meta{position()}">
      <rdfs:label><xsl:value-of select="@content"/></rdfs:label>
      <xsl:call-template name="proc-keyword">
       <xsl:with-param name="s" select="@content"/>
      </xsl:call-template>
     </wm:WordSet>
    </wm:keywordSet>
   </xsl:when>
  </xsl:choose>
  <!--@ note: @name='author' will be treated by template who, not here (注：authorは別のテンプレートで)  -->
 </xsl:template>

 <xsl:template match="h:link">
  <!--** Link elements with a predefined relation (link要素の処理). Steps: -->
  <xsl:choose>

   <!--@ case: @rel='copyright', generates dc:rights (copyrightはdc:rightsに) -->
   <xsl:when test="@rel='copyright'">
    <dc:rights>
     <xsl:attribute name="rdf:resource"><xsl:value-of select="@href"/></xsl:attribute>
    </dc:rights>
   </xsl:when>

   <!--@ case: @rel='alternate', then (alternateのときは): -->
   <xsl:when test="@rel='alternate'">
    <xsl:choose>
     <!--@ _ if @hreflang presents, generates dct:hasVersion (@hreflanがあればdct:hasVersion) -->
     <xsl:when test="@hreflang">
      <dct:hasVersion>
       <xsl:attribute name="rdf:resource"><xsl:value-of select="@href"/></xsl:attribute>
       <xsl:attribute name="dc:lang"><xsl:value-of select="@hreflang"/></xsl:attribute>
      </dct:hasVersion>
     </xsl:when>
     <!--@ _ if @type contains '+xml', generates rdfs:seeAlso (@typeが'+xml'含むときはrdfs:seeAlso) -->
     <xsl:when test="contains(@type,'+xml')">
      <rdfs:seeAlso>
       <xsl:attribute name="rdf:resource"><xsl:value-of select="@href"/></xsl:attribute>
       <xsl:if test="@title">
        <xsl:attribute name="rdfs:label"><xsl:value-of select="@title"/></xsl:attribute>
       </xsl:if>
      </rdfs:seeAlso>
     </xsl:when>
    </xsl:choose>
   </xsl:when>

   <!--@ case: @rel='meta' and @type='application/rdf+xml' and not(@title='FOAF'), generates rdfs:seeAlso (@title='FOAF' will be treated by template who) 
   (metaで@type='application/rdf+xml'でかつ@titleが'FOAF'でないときはrdfs:seeAlso) -->
   <xsl:when test="@rel='meta' and @type='application/rdf+xml' and not(@title='FOAF')">
    <rdfs:seeAlso>
     <xsl:attribute name="rdf:resource"><xsl:value-of select="@href"/></xsl:attribute>
     <xsl:if test="@title">
      <xsl:attribute name="rdfs:label"><xsl:value-of select="@title"/></xsl:attribute>
     </xsl:if>
    </rdfs:seeAlso>
   </xsl:when>

   <!--@ case: call proc-rel -->
   <xsl:otherwise>
    <xsl:call-template name="proc-rel">
     <xsl:with-param name="rel" select="@rel"/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
  <!--@ note: @rev='made' will be treated by template who, and @rel='schema.pfx' by findns,  not here (他のテンプレートで扱うものもあり)  -->
 </xsl:template>



 <!--================== proc XHTML body and weblog entry ==================-->


 <xsl:template match="h:body">
  <!--** Generates document metadata and finds blocks (topics). Steps:-->
  <!--@ find table of contents -->
  <xsl:call-template name="toc"/>
  <!--@ test if the body has multple weblog entries -->
  <xsl:choose>
   <xsl:when test="count(.//h:div[contains(&articleclass;, &classnames;)]) &gt; 1">
    <!--@ if yes, proc each entry which is a topic of the document (ignoring other blocks) -->
   <xsl:apply-templates select=".//h:div[contains(&articleclass;, &classnames;)]" mode="entry"/>
   </xsl:when>
   <xsl:otherwise>
    <!--@ else, get metadata topics for the document from block level elements -->
    <!--no inline element should present here!-->
    <xsl:apply-templates select="&hblockelt;"/>
   </xsl:otherwise>
  </xsl:choose>
  <xsl:call-template name="refs"/><!--＠＠ in case reflist is defined by @id-->

 </xsl:template>


 <xsl:template match="h:div[contains(&articleclass;, &classnames;)]" mode="entry">
  <!--** Processes an weblog entry block as topic for the document. 
  (ウェブログで一般的なクラス名を持つdiv要素の処理) Steps:-->
  <!--@ generates document property (foaf:topic) and a topic node (rdf:Description) -->
  <foaf:topic>
   <rdf:Description>
    <!--@ finds a subject URI for this entry, e.g. let parmalink be a[@class='about'] 
    (恒久リンクにclass='about'を与えておくと、主語URIを一致させることができる)-->
    <xsl:call-template name="get-subject"/>
    <!--@ finds a title for this entry (タイトルに相当する要素を探す)-->
    <xsl:call-template name="find-title">
     <xsl:with-param name="prop" select="'dc:title'"/>
    </xsl:call-template>
    <!--@ find metadata from inline constructs for this entry -->
    <xsl:apply-templates select="&hinlineelt;"/>
    <!--＠＠@ treats all external links as dct:references (test)
    <xsl:call-template name="find-reflink"/>
     -->
    <!--@ and process nested block level elements -->
    <xsl:apply-templates select="&hblockelt;"/>
   </rdf:Description>
  </foaf:topic>
 </xsl:template>




 <!--================== metadata from block level elements ==================-->

 <xsl:template match="h:*[contains(&blockelt;, &localnames;)]">
  <!--** A common 'catch all' for a blocklevel element (一般的なブロックレベル要素＝classを持たない＝は素通りして子要素処理のテンプレート呼び出し) -->
  <xsl:apply-templates select="&hinlineelt;"/>
  <xsl:apply-templates select="&hblockelt;"/>
 </xsl:template>

 <xsl:template match="h:table" priority="-0.5">
  <!--** in case a <table> skip tbody,tr and directly goes into cells. Priority is set low in order to process microformats if <table> has class='vcard' etc. (tableの場合は、tbodyがあったりなかったりするので、直接th|tdを処理する)-->
  <!-- ＠＠tr単位でクラスを与えたいときはどうする？-->
  <xsl:apply-templates select=".//h:th|h:td"/>
 </xsl:template>


 <xsl:template match="h:blockquote[@cite]">
  <!--** blockquote with @cite attribute will be a dct:references (blockquoteがcite属性を持つときは参照リンクを加える)-->
  <dct:references rdf:resource="{@cite}">
   <xsl:if test="@title">
    <xsl:attribute name="dc:title"><xsl:value-of select="@title"/></xsl:attribute>
   </xsl:if>
  </dct:references>
  <xsl:apply-templates select="&hinlineelt;"/>
  <xsl:apply-templates select="&hblockelt;"/>
 </xsl:template>


 <xsl:template match="h:*[contains(&blockelt;, &localnames;)][@class]">
  <!--** Block level element with a general (non microformats) @class (一般的な＝veventなどのマイクロフォーマットでない＝@classを持つブロックレベル要素). Steps: -->
  <xsl:choose>
   <!--@ case: the first letter of @class name is capital, generates WordNet Classes. It must be the first token if space separated class list is used (大文字で始まるclass属性値を持つブロックレベル要素をWordNetクラスの型付ノード要素として処理). -->
   <!-- ＠＠WordNetがいいのかどうか-->
   <xsl:when test="contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring(@class,1,1))">
    <xsl:call-template name="gen-class">
     <xsl:with-param name="attrs" select="concat('wn.',@class)"/>
    </xsl:call-template>
   </xsl:when>
   <xsl:when test="contains(@class,'.')">
   <!--@ case: schema prefixed @class name. It is not necessarily be the first token, but only the first prefixed token will be processed (ピリオドを含むclass属性値なら): -->

    <xsl:choose>
     <!--@ _ if the class name starts with capital letter, then RDF Class (typed node, call gen-class), which will be related to the document with foaf:topic -->
     <xsl:when test="contains('ABCDEFGHIJKLMNOPQRSTUVWXYZ', substring(substring-after(@class,'.'),1,1))">
      <xsl:call-template name="gen-class">
       <xsl:with-param name="attrs" select="@class"/>
      </xsl:call-template>
     </xsl:when>
     <!--@ _ otherwise RDF Property (call gen-prop). Note that if @class contains two prefixed tokens, the first will be property, and the second will be nested Class element. See gen-prop. In this way, you can specify the property that relates the document and this block level element (接頭辞付小文字属性値はプロパティになるが、接頭辞付き属性値がもうひとつあると、2番目は目的語のクラスとして扱われる。) -->
     <xsl:otherwise>
      <xsl:call-template name="gen-prop">
       <xsl:with-param name="props" select="@class"/>
      </xsl:call-template>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <!--@ otherwise: not creating a node for this block element, just processes children (いずれも一致しなければノードは作らずに子要素を処理) -->
   <xsl:otherwise>
    <xsl:apply-templates select="&hinlineelt;"/>
    <xsl:apply-templates select="&hblockelt;"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>




 <!--================== metadata from microformats ==================-->

 <xsl:template match="h:*[contains('&core-and-tbl;address|', &localnames;)][contains(@class,'vcard')]">
  <!--** for hCard, generates foaf:Person as foaf:topic, and calls template hcard-elt -->
  <foaf:topic>
   <foaf:Person >
    <xsl:call-template name="get-subject"/>
    <xsl:call-template name="hcard-elt"/>
   </foaf:Person>
  </foaf:topic>
 </xsl:template>

 <xsl:template match="h:*[contains('&core-and-tbl;', &localnames;)][contains(@class,'vevent')]">
  <!--** for hCalendar, generates foaf:topic, and calls template proc-hcal -->
  <foaf:topic>
   <xsl:call-template name="proc-hcal"/>
  </foaf:topic>
 </xsl:template>

 <xsl:template match="h:*[contains('&core-and-tbl;', &localnames;)][contains(@class,'hreview')]">
  <!--** for hReview, generates foaf:topic, and calls template proc-hreview -->
  <foaf:topic>
   <xsl:call-template name="proc-hreview"/>
  </foaf:topic>
 </xsl:template>

 <!-- microformats will be processed by imported templates.  -->
 <xsl:include href="./micro-model.xsl"/>



 <!--================== metadata from inline elements ==================-->

 <xsl:template match="*[contains(&inlineelt;, &localnames;)]">
  <!--** %catch all for inline element (to process nested elements) (@classや@relのないインライン要素は素通りして子インライン要素を処理するテンプレートを呼び出す)-->
  <xsl:apply-templates select="&hinlineelt;"/>
 </xsl:template>

 <xsl:template match="*[contains(&inlineelt;, &localnames;)][@class][not(@rel)]">
  <!--** Gets Property from general schema prefixed @class (but no @rel) of an inline element. Note this also applied to <a> with @class but not @rel. (@classがあって@relのないインライン要素は、gen-propを呼び出してプロパティが生成できるかどうか調べる) -->
  <xsl:call-template name="gen-prop">
   <xsl:with-param name="props" select="@class"/>
  </xsl:call-template>
 </xsl:template>



 <!--================== metadata from predefined classes ==================-->

 <xsl:template match="h:*[@class='me']" mode="who">
  <!--** Special paragraph that talks about the author of the document (@class='me'である要素は文書作者に関する情報として扱う。これはwhoテンプレートでlink要素と合わせて呼び出される)-->
<!--
  <xsl:apply-templates select=".//h:a[contains(@rel,'.')]"/>
  <xsl:apply-templates select=".//*[contains(@class,'.')][not(@rel)]"/>
  <xsl:call-template name="hcard-elt"/>
-->
  <xsl:call-template name="proc-rel">
   <xsl:with-param name="rel" select="@rel"/>
  </xsl:call-template>
  <xsl:call-template name="gen-prop">
   <xsl:with-param name="props" select="@class"/>
  </xsl:call-template>
    <xsl:apply-templates select="&hinlineelt;"/>
    <xsl:apply-templates select="&hblockelt;"/>
 </xsl:template>

 <xsl:template match="h:*[@class='me']">
  <!--** @class='me' should only be processed from within template 'who' (whoテンプレートからの呼び出しで処理するので、本文処理中の@class='me'は無視する)-->
  <!--＠＠効率悪いかな-->
 </xsl:template>


 <xsl:template match="h:dfn">
  <!--** DFN is regardes as a kind of keyword of this document (dfn要素は一種のキーワードとして)-->
  <wm:definitionSet>
   <wm:WordSet rdf:about="#_dfns">
    <xsl:if test="position()=1"><rdfs:label>terms defined in this document</rdfs:label></xsl:if>
    <xsl:call-template name="proc-keyword">
     <xsl:with-param name="s" select="."/>
    </xsl:call-template>
   </wm:WordSet>
  </wm:definitionSet>
 </xsl:template>

 <xsl:template name="proc-keyword">
  <!--** generates 'linked keywords' (recursively if separated by commas) (カンマで区切られた文字列を複数のキーワードとして扱い、再帰的に処理する)-->
  <xsl:param name="s"/>
  <xsl:variable name="kw">
   <xsl:choose>
    <xsl:when test="contains($s,',')">
     <xsl:value-of select="substring-before($s,',')"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$s"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="rest" select="substring-after($s,',')"/>
  <xsl:call-template name="keyword-elt">
   <xsl:with-param name="term" select="$kw"/>
  </xsl:call-template>
  <xsl:if test="not($rest='')">
   <xsl:call-template name="proc-keyword">
    <xsl:with-param name="s" select="$rest"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>


 <xsl:template name="keyword-elt">
  <!--** an experimental wm:associatedWord property for WordSet (meta, dfn, @rel='tag' generates a sort of 'keywordSet' property whose object is an instanse of wm:WordSet, then it will be associated each 'Word' resource)
  (meta, dfn, @rel='tag'はプロパティ'keywordSet'を生成し、その目的語であるWordSetはそれぞれの単語にwm:associatedWordで結ばれる) -->
  <!-- e.g.
    <meta name="keywords" conent="RDF,XSLT"/> will generate something
    <> wm:keywordSet 
         [a wm:WordSet;
          wm:associatedWord psi:RDF, psi:XSLT ] .
   -->
  <xsl:param name="term"/><!--** keyword -->
  <xsl:param name="ref"/><!--** optional original link for the keyword, e.g. <a rel="tag"... -->
  <xsl:variable name="nterm" select="normalize-space($term)"/>
  <!--xsl:variable name="kwuri" select="concat('http://www.kanzaki.com/ns/keyword/',translate($nterm,' ','_'),'#word')"/-->
  <xsl:variable name="kwuri" select="concat('http://www.kanzaki.com/ns/keyword/',translate($nterm,' ','_'))"/>
  <xsl:choose>
   <xsl:when test="$ref=''">
    <wm:associatedWord rdf:resource="{$kwuri}" rdfs:label="{$nterm}"/>
   </xsl:when>
   <xsl:otherwise>
    <wm:associatedWord>
     <wm:Word rdf:about="{$kwuri}">
      <rdfs:label><xsl:value-of select="$nterm"/></rdfs:label>
      <dc:relation rdf:resource="{$ref}"/>
     </wm:Word>
    </wm:associatedWord>
   </xsl:otherwise>
  </xsl:choose>
  <!--
  <xsl:variable name="lang">
   <xsl:choose>
    <xsl:when test="lang('ja')">ja</xsl:when>
    <xsl:otherwise>en</xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <wm:hasKeyword rdf:parseType="Resource">
   <rdfs:label><xsl:value-of select="$nterm"/></rdfs:label>
   <wm:someSenseDescribedBy rdf:resource="http://{$lang}.wikipedia.org/wiki/{$nterm}"/>
  </wm:hasKeyword>
  -->
 </xsl:template>


 <xsl:template match="h:*[@class='abstract']">
  <!--** Abstract of the content of this document (@class='abstract'を持つ要素は文書の要約とみなす)-->
  <dct:abstract><xsl:value-of select="normalize-space(.)"/></dct:abstract>
  <xsl:apply-templates select="&hinlineelt;"/>
 </xsl:template>



 <xsl:template match="h:ul[@class='rss-items']">
  <!--** generates RSS items from XHTML ul element. hmm... throw away ?-->
  <rss:items xmlns:rss="http://purl.org/rss/1.0/">
   <rdf:Bag>
    <xsl:for-each select="h:li">
     <rdf:li rdf:resource="{h:a/@href}" rdfs:label="{h:a}"/>
    </xsl:for-each>
   </rdf:Bag>
  </rss:items>
 </xsl:template>




 <!--================== Reference and publication list block ==================-->

 <xsl:template match="h:*[contains('|&listelt;', &localnames;)][@class='refs' or @class='bib']">
  <!--** list element as bibliographic reference list. When a list has a class="refs" and children include <cite> elements, then it will be a bibliographic resource list. See template 'reflist' for detailed rules. (リスト要素がclass="refs"を持ち、子要素内に<cite>要素が含まれていれば、参照文献リストを生成できます。詳細はテンプレートreflistを参照) -->
  <xsl:call-template name="reflist">
   <xsl:with-param name="nodes" select="h:*[h:cite]"/>
   <xsl:with-param name="prop" select="'dct:references'"/>
  </xsl:call-template>
 </xsl:template>


 <xsl:template match="h:*[contains('|&listelt;', &localnames;)][@class='pubs']">
  <!--** list element as publication list. When a list has a class="pubs" and children include <cite> elements, then it will be a bibliographic resource list. See also following template rules. (リスト要素がclass="pubs"を持ち、子要素内に<cite>要素が含まれていれば、成果物リストを生成できます。) -->
  <xsl:call-template name="reflist">
   <xsl:with-param name="nodes" select="h:*[h:cite]"/>
   <xsl:with-param name="prop" select="'foaf:made'"/>
  </xsl:call-template>
 </xsl:template>

 <xsl:template name="refs">
  <!--** in case the reference list is defined by @id='references', such as some W3C specs -->
  <xsl:if test="h:*[@id='references']">
   <xsl:call-template name="reflist">
    <xsl:with-param name="nodes" select="h:*[@id='references']/following-sibling::h:dl/h:dd"/>
    <xsl:with-param name="prop" select="'dct:references'"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>

 <xsl:template name="reflist">
  <!--** generates references from specified nodes (e.g. list member elements). A child cite element will be the title (and link if present), and other children with @class will be treated according to general @class rules. (ノード集合から参照グラフを生成。子要素にcite要素があればタイトルを、その内部にa要素があればリンクを生成。そのほか@classを持つ子要素は通常のルールに従って処理) Steps: -->
  <xsl:param name="nodes"/><!--** node list of references -->
  <xsl:param name="prop"/><!--** propety to connect the document and each reference -->
  <xsl:for-each select="$nodes">
   <xsl:element name="{$prop}">
    <rdf:Description>
     <xsl:if test="h:cite/h:a[@href]">
      <!--@ if a <cite> has a child <a>, this is a reference to online resource (cite要素内にa要素のリンクがあれば、リソースの主語URIにする) -->
      <xsl:attribute name="rdf:about">
       <xsl:value-of select="h:cite/h:a/@href"/>
      </xsl:attribute>
     </xsl:if>
     <!--@ a <cite> element will be a dc:title property (cite要素の内容はdc:title。cite内にaがあっても同じ) -->
     <dc:title><xsl:value-of select="normalize-space(h:cite)"/></dc:title>
     <!--@ other elements with class name from DC (i.e. creator, date, etc) will be corresponding dc:* property. Special case: 'author' will be dc:creator. (そのほかの@classは通常のルールに従う。たとえば、@class='date'があれば日付、@class='creator'があれば作者リンク)-->
     <xsl:apply-templates select="h:*[@class]"/>
    </rdf:Description>
   </xsl:element>
  </xsl:for-each>
 </xsl:template>







 <!--================== metadata from rel attributes ==================-->

 <xsl:template match="h:a[@rel]">
  <!--** processes <a> element with @rel value. -->
  <!-- call proc-rel to process space separated @rel tokens -->
  <xsl:call-template name="proc-rel">
   <xsl:with-param name="rel" select="@rel"/>
  </xsl:call-template>
  <!-- ＠＠検討74：if it has class='title'
  <xsl:if test="@class='title'">
   <dc:title><xsl:call-template name="get-label"/></dc:title>
  </xsl:if>
  -->
  <!-- ＠＠これは単なる重複処理では？
  <xsl:call-template name="gen-prop">
   <xsl:with-param name="props" select="@class"/>
  </xsl:call-template>
  -->
 </xsl:template>

 <xsl:template match="h:a[@rel][@class='about']">
  <!--** do nothing, because h:a[@class='about'] is to be treated as subject in ancestor block. Be careful when @class='ifp' for parent block - if this a element has @rel, it will generate duplicated property. See template 'get-subject' -->
  <!-- get-subject参照。rel="work"やrel="section"を大きなdivに入れたいときはどうしようか＠＠ -->
 </xsl:template>


 <xsl:template name="proc-rel">
  <!--** processes each of space separated @rel tokens. (@rel属性の各値を順番に処理) Steps: -->
  <xsl:param name="rel"/>
  <!--@ set $r as one name from a list of space separated @rel value (空白区切りの属性値リストから最初の1つを取り出して変数$rにセット)-->
  <xsl:variable name="r">
   <xsl:choose>
    <xsl:when test="contains($rel,' ')">
     <xsl:value-of select="substring-before($rel,' ')"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$rel"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="rest" select="substring-after($rel,' ')"/>


  <!--@ check the value of one token, and generate appropriate property:  -->
  <xsl:choose>
   <xsl:when test="$r=''">
   </xsl:when>
   <!--@ _ License URI: 'license' will be xhv:license -->
   <xsl:when test="$r='license'">
    <xhv:license rdf:resource="{@href}"/>
   </xsl:when>

   <!--@ _ Document Topic: 'topic' or 'foaf.topic' will be foaf:topic -->
   <xsl:when test="$r='topic' or $r='foaf.topic'">
    <foaf:topic>
    <!--
     <xsl:attribute name="rdfs:label">
      <xsl:call-template name="get-label"/>
     </xsl:attribute>
     -->
     <!--@ __ this case, call proc-prop-body to generate proper element form @class -->
     <xsl:call-template name="proc-prop-body">
      <xsl:with-param name="type" select="@class"/>
     </xsl:call-template>
    </foaf:topic>
   </xsl:when>

   <!--@ _ Authors with URI: creator, publisher, contributor will generate corresponding dc: property with an entity as its object (not reteral) plus IFP (call gen-prop) -->
   <!-- $r=''はテスト済み。実体参照の前後に''をつけることに注意-->
   <xsl:when test="contains('&dcwho;', $r)">
    <xsl:call-template name="gen-prop">
     <xsl:with-param name="props" select="$r"/><!--concat('dc.',$r)-->
     <xsl:with-param name="type" select="'ifp'"/>
    </xsl:call-template>
   </xsl:when>

   <!--@ _ Dublin Core relations: most dc names used as @rel will generate corresponding dc: property with an entity as its object whose type is value of @class (call gen-prop) -->
   <xsl:when test="contains(&dcrel;, $r)">
    <xsl:call-template name="gen-prop">
     <xsl:with-param name="props" select="concat('dc.',$r)"/>
     <xsl:with-param name="type" select="@class"/>
    </xsl:call-template>
   </xsl:when>

   <!--@ _ Dublin Core Terms relations: references, isPartOf, hasPart will generate corresponding dc: property with an entity as its object whose type is value of @class (call gen-prop) -->
   <xsl:when test="contains(&dctrel;, $r)">
    <xsl:call-template name="gen-prop">
     <xsl:with-param name="props" select="concat('dcterms.',$r)"/>
     <xsl:with-param name="type" select="@class"/>
    </xsl:call-template>
   </xsl:when>

   <!--@ _ Tags: 'tag' will generate wm:tagSet and calls keyword-elt template -->
   <xsl:when test="$r='tag'">
    <wm:tagSet>
     <wm:WordSet rdf:about="#_tags">
      <xsl:call-template name="keyword-elt">
       <xsl:with-param name="type" select="@class"/>
       <xsl:with-param name="term" select="."/>
       <xsl:with-param name="ref" select="@href"/>
      </xsl:call-template>
     </wm:WordSet>
    </wm:tagSet>
   </xsl:when>

   <!--@ _ Sitemap relation: related, section, work will generate sitemap properties. If @class contains prefix 'sitemap.', the object node will be of that type. -->
   <xsl:when test="contains('|related|section|work|next|prev|subsection|',concat('|',$r,'|'))">
<!--
    <xsl:variable name="p">
     <xsl:choose>
      <xsl:when test="@rel='section'">sitemap:isSubsectionOf</xsl:when>
      <xsl:when test="@rel='subsection'">sitemap:subsection</xsl:when>
     </xsl:choose>
    </xsl:variable>
-->
    <xsl:element name="sitemap:{$r}">
     <xsl:attribute name="rdf:resource">
      <xsl:value-of select="@href"/>
     </xsl:attribute>
     <xsl:attribute name="rdfs:label">
      <xsl:call-template name="get-label"/>
     </xsl:attribute>
     <!-- ＠＠今のところ.付き@classでもrdf:typeを生成しない -->
     <xsl:if test="starts-with(@class,'sitemap.')">
      <xsl:attribute name="rdf:type"><xsl:value-of select="concat('&sitemap;',substring-after(@class,'.'))"/></xsl:attribute>
     </xsl:if>
    </xsl:element>
   </xsl:when>

   <!--@ _ General relation: finally, if @rel is not one of the above but contains '.', it will use @rel as property and @class as object type (call gen-prop) -->
   <xsl:when test="contains($r, '.')">
    <xsl:call-template name="gen-prop">
     <xsl:with-param name="props" select="$r"/>
     <xsl:with-param name="type" select="@class"/>
    </xsl:call-template>
   </xsl:when>

  </xsl:choose>

  <!--@ If more value(s) in @class list, then process them recursively. (空白で区切られた属性値リストのときは、2番目以降の値を引数として再起呼び出しを行う)-->
  <xsl:if test="$rest">
   <xsl:call-template name="proc-rel">
    <xsl:with-param name="rel" select="$rest"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>



 <!--================== Property Generators ==================-->

 <xsl:template name="gen-prop">
  <!--** Generates Property from schema prefixed @class/@rel(再起呼び出ししながら@class/@relからプロパティ要素を生成していく。属性値に'.'を含むときのみ、要素を生成。). Steps: -->
  <xsl:param name="props"/><!--** @class/@rel (@class/@rel属性値＝プロパティ名)-->
  <xsl:param name="type"/><!--** @class if called from a template for 'a' (さらに<a>要素で@relに加えて@classがある場合はこのパラメータを使う＝プロパティの目的語の型)-->
  
  <!--@ set $p as one name from a list of space separated @class/@rel value (空白区切りの属性値リストから最初の1つを取り出して変数$pにセット)-->
  <xsl:variable name="p">
   <xsl:choose>
    <xsl:when test="contains($props,' ')">
     <xsl:value-of select="substring-before($props,' ')"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$props"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>

  <!--@ set $rest as the rest of token list (2番目以降の属性値リストを変数$restにセット)-->
  <xsl:variable name="rest" select="substring-after($props,' ')"/>

  <!--@ set $child-type if param $type is given, or $rest contains '.', i.e. if @class has second dot prefixed token, it will be treated as child class name ($typeもしくは'.'を含む$restがあれば$child-typeにセット。つまり、接頭辞付きクラス名を2つ用いると、2つ目がプロパティの子要素としてクラスとなる)-->
  <xsl:variable name="child-type">
   <xsl:choose>
    <xsl:when test="$type !=''"><xsl:value-of select="$type"/></xsl:when>
    <xsl:when test="contains($rest,'.')"><xsl:value-of select="$rest"/></xsl:when>
   </xsl:choose>
  </xsl:variable>


  <!--@ Switch according to $p value: -->
  <xsl:choose>
   <xsl:when test="$p=''">
   </xsl:when>
   <!--@ _ case: the name is schema prefixed, resolve namespace (call find-ns): ('.'を含む名前の処理を行う。まず名前空間を解決)-->
   <xsl:when test="contains($p,'.')">
    <xsl:variable name="ns">
     <xsl:call-template name="find-ns">
      <xsl:with-param name="pfx" select="substring-before($p,'.')"/>
     </xsl:call-template>
    </xsl:variable>
    <xsl:if test="not($ns='')">
     <!--@ __ if namespace is resolved, then generates a property element (call proc-prop-body)
      (名前空間が解決されたら、要素生成に進む) -->
     <xsl:element name="{translate($p,'.',':')}" namespace="{$ns}">
      <xsl:call-template name="proc-prop-body">
       <xsl:with-param name="type" select="$child-type"/>
      </xsl:call-template>
     </xsl:element>
    </xsl:if>
   </xsl:when>

   <!--@ _ case: $p contains dc: names, sub-switch: -->
   <xsl:when test="contains(&dcclass;, concat('|',$p,'|'))">
    <xsl:choose>
     <xsl:when test="$p='author'">
      <!--@ __ if 'author', then literal value of dc:creator. Note this can have multiple authors. [Testing] generate a (group) entity, then resolve by referenced script (/ns/names) -->
      <!--
      <dc:creator><xsl:value-of select="."/></dc:creator>
      -->
      <xsl:call-template name="gen-entity">
       <xsl:with-param name="prop" select="'dc:creator'"/>
       <xsl:with-param name="type" select="'foaf:Agent'"/>
       <xsl:with-param name="a-type" select="$type"/>
      </xsl:call-template>
     </xsl:when>
     <xsl:when test="contains('&dcwho;', concat('|',$p,'|'))">
      <!--@ __ if 'creator' or 'publisher' or 'contributor', then entity value of corresponding dc:* (call gen-entity). Note entity will be foaf:Agent, not foaf:Person. If multiple name presents, it will be interpreted as a foaf:Group.-->
      <xsl:call-template name="gen-entity">
       <xsl:with-param name="prop" select="concat('dc:',$p)"/>
       <xsl:with-param name="type" select="'foaf:Agent'"/>
       <xsl:with-param name="a-type" select="$type"/><!-- supposed to be 'ifp'＠＠この入れ替えはトリッキー -->
       <!--
       <xsl:with-param name="labelattr">
        <xsl:choose>
         <xsl:when test="contains(.,',')">rdfs:label</xsl:when>
         <xsl:otherwise>foaf:name</xsl:otherwise>
        </xsl:choose>
       </xsl:with-param>
       -->
      </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
      <!--@ __ otherwise: simple literal property of dc:*. Tips: do not use dot prefixed class for <a> without @rel, because this will be processed previous rule, and generate entity with URI (e.g. dc:identifier has URI entity as its object. Use @class='identifier' instead. -->
      <xsl:element name="{concat('dc:', $p)}">
       <xsl:call-template name="get-label"/>
      </xsl:element>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when><!-- end contains(&dcclass;, $p)-->
   
   <xsl:when test="$p='label'">
    <!--@ _ case: 'label', it is treated as rdfs:label -->
    <xsl:element name="rdfs:label">
     <xsl:value-of select="."/>
    </xsl:element>
   </xsl:when>

   <xsl:when test="$p='created' or $p='modified'">
    <!--@ _ case: 'created' or 'modified', creation/modification date of this document -->
    <xsl:element name="dct:{$p}">
     <xsl:value-of select="substring(.,1,10)"/>
    </xsl:element>
   </xsl:when>

   <xsl:when test="$p='subject'">
    <!--@ _ case: 'subject', it is treated as keyword (call keyword-elt. cf. dc:subject if @rel) -->
    <xsl:call-template name="keyword-elt">
     <xsl:with-param name="term" select="."/>
    </xsl:call-template>
   </xsl:when>

 </xsl:choose>

  <!--@ If more value(s) in @class list, then process them recursively. (空白で区切られた属性値リストがあれば、2番目以降の値を引数として再起呼び出しを行う)-->
  <xsl:if test="$rest and $child-type=''">
   <xsl:call-template name="gen-prop">
    <xsl:with-param name="props" select="$rest"/>
   </xsl:call-template>
  </xsl:if>
 </xsl:template>





 <xsl:template name="proc-prop-body">
<!--** generates attributes and child elements of property node (プロパティノードの属性や子要素を処理する). Steps:-->
  <xsl:param name="type"/><!--** type of elt, derived from @class of <a>, or second token of @class list -->
  
  <xsl:if test="@xml:lang">
   <xsl:attribute name="xml:lang"><xsl:value-of select="@xml:lang"/></xsl:attribute>
  </xsl:if>
  <xsl:choose>
   <!--@ if dot prefixed $type is specified (i.e the element is 'a' and has pfxed name for @class, or the element is block level and two prefixed @class values are given), then it is a typed node (call gen-class-elt). (<a>要素から呼ばれるときの$typeに'.'が含まれていれば、gen-class-eltを呼んで型付要素ノードにする) -->
   <xsl:when test="contains($type,'.')">
    <xsl:call-template name="gen-class-elt">
     <xsl:with-param name="c" select="$type"/>
    </xsl:call-template>
   </xsl:when>
   <!--@ if no @href, a literal property (@hrefがないときはリテラルプロパティ). -->
   <xsl:when test="not(@href)">
    <xsl:call-template name="get-label"/>
   </xsl:when>
   <xsl:otherwise>
   <!--@ else, generates object node element (@hrefがあれば、さらにノード要素/属性も生成する). switch: -->
    <xsl:choose>
     <!--@ _ case: the element is 'a' and has pfxed name for @class, it is a typed node (call gen-class-elt). (<a>要素から呼ばれるときの$typeに'.'が含まれていれば、gen-class-eltを呼んで型付要素ノードにする) -->
 <!--    <xsl:when test="contains($type,'.')">
      <xsl:call-template name="gen-class-elt">
       <xsl:with-param name="c" select="$type"/>
      </xsl:call-template>
     </xsl:when>-->
     <!--@ _ case: elt is 'a' and has @class='ifp', it is foaf:homepage ($typeが'ifp'のときは、URIをfoaf:homepageの値にして逆関数プロパティをつくる). -->
     <xsl:when test="contains($type,'ifp')">
     <!--＠＠ここで型付ノードを作りたいときは？-->
      <rdf:Description>
       <foaf:homepage rdf:resource="{@href}"/>
       <rdfs:label><xsl:call-template name="get-label"/></rdfs:label>
      </rdf:Description>
     </xsl:when>
     <!--@ _ otherwise: rdf:Description with @href as rdf:about. (それ以外の目的語は、rdf:Description) -->
     <xsl:otherwise>
     <!--
      <xsl:attribute name="rdf:resource"><xsl:value-of select="@href"/></xsl:attribute>
      <xsl:attribute name="rdfs:label"><xsl:call-template name="get-label"/></xsl:attribute>
      -->
      <rdf:Description rdf:about="{@href}">
       <xsl:if test="not($type='title')"><!-- ＠＠検討74：@class='title'のときは親ノードのタイトル-->
        <rdfs:label><xsl:call-template name="get-label"/></rdfs:label>
       </xsl:if>
      </rdf:Description>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>






 <!--================== named templates for specific purposes ==================-->

 <xsl:template name="get-label">
  <!--** get a label of a resource, from @title if presents, otherwise from content of the element (リソースのラベルを@titleもしくは要素内容から生成)-->
  <xsl:choose>
   <xsl:when test="@title"><xsl:value-of select="@title"/></xsl:when>
   <xsl:otherwise><xsl:value-of select="normalize-space(.)"/></xsl:otherwise>
  </xsl:choose>
 </xsl:template>


 <xsl:template name="find-title">
  <!--** Tries to find a title for a weblog entry (ウェブログのブロックなどから呼ばれ、ラベルとなるべきタイトルを推定する). Steps:-->
  <xsl:param name="prop"/><!--** label property -->
  <!--@ determines the label property (if $prop provided, use it. otherwise rdfs:label)-->
  <xsl:variable name="labelprop">
   <xsl:choose>
    <xsl:when test="$prop"><xsl:value-of select="$prop"/></xsl:when>
    <xsl:otherwise>rdfs:label</xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="title">
   <xsl:choose>
    <!--@ If a @title found in the block, it will be a title, -->
    <xsl:when test="@title">
     <xsl:value-of select="@title"/>
    </xsl:when>
    <!--@ else if an <h2> found in the block, first of it will be a title, -->
    <xsl:when test="h:h2">
     <xsl:value-of select="h:h2"/>
    </xsl:when>
    <!--@ else if an <h3> found in the block, first of it will be a title, -->
    <xsl:when test="h:h3">
     <xsl:value-of select="h:h3"/>
    </xsl:when>
    <!--@ else try to find a nearest preceding <h3>, -->
    <xsl:when test="preceding-sibling::h:h3">
     <xsl:value-of select="preceding-sibling::h:h3[1]"/>
    </xsl:when>
    <!--@ finally try to find a nearest preceding <h2>. -->
    <xsl:when test="preceding-sibling::h:h2">
     <xsl:value-of select="preceding-sibling::h:h2[1]"/>
    </xsl:when>
   </xsl:choose>
  </xsl:variable>
  <!--@ If any title found, then dc:title. -->
  <xsl:if test="not($title='')">
   <xsl:element name="{$labelprop}"><xsl:value-of select="$title"/></xsl:element>
  </xsl:if>
 </xsl:template>

<!--** generates dct:references for all links within an weblog entry. maybe too many rerefences ? NOT IN USE.
 <xsl:template name="find-reflink">
  <xsl:for-each select=".//h:a">
   <xsl:choose>
    <xsl:when test="@class='permalink'">
     <dct:hasVersion rdf:resource="{@href}"/>
    </xsl:when>
    <xsl:when test="starts-with(@href,'http:')">
     <dct:references rdf:resource="{@href}">
      <xsl:attribute name="rdfs:label">
       <xsl:call-template name="get-label"/>
      </xsl:attribute>
     </dct:references>
    </xsl:when>
   </xsl:choose>
  </xsl:for-each>
 </xsl:template>
 -->

 <xsl:template name="toc">
  <!--** generates a table of contents of this document. Steps: -->
  <xsl:choose>
   <!--@ If an <ul> with class='toc' or id='toc', use <li>'s as param for gen-toc -->
   <xsl:when test=".//h:ul[@class='toc' or @id='toc']">
    <xsl:call-template name="gen-toc">
     <xsl:with-param name="li" select=".//h:ul[@class='toc']/h:li"/>
    </xsl:call-template>
   </xsl:when>
   <!--@ otherwise, use <h2>'s in the document as param for gen-toc -->
   <xsl:otherwise>
    <xsl:call-template name="gen-toc">
     <xsl:with-param name="li" select=".//h:h2"/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>


 <xsl:template name="gen-toc">
  <!--** Generates a MARC field 505 style TOC of this document as dct:tableOfContents -->
  <xsl:param name="li"/>
  <xsl:variable name="nc" select="count($li)"/>
  <xsl:variable name="toc">
   <xsl:for-each select="$li">
    <xsl:value-of select="h:img/@alt"/>
    <xsl:value-of select="normalize-space(.)"/>
    <!-- MARC field 505 style list -->
    <xsl:choose>
     <xsl:when test="position()=$nc"> .</xsl:when>
     <xsl:otherwise> -- </xsl:otherwise>
    </xsl:choose>
   </xsl:for-each>
  </xsl:variable>
  <xsl:if test="not($toc='')">
   <dct:tableOfContents>
    <xsl:copy-of select="$toc"/>
   </dct:tableOfContents>
  </xsl:if>
 </xsl:template>





 <xsl:template name="gen-entity">
  <!--** Generates entity-relashionship style model from a literal element. Steps: -->
  <xsl:param name="prop"/><!--** property -->
  <xsl:param name="type"/><!--** class (type) of the object node -->
  <xsl:param name="a-type"/><!--** original @class from <a> with @rel -->
  <xsl:variable name="name"><!--** label of object (call get-label) -->
   <xsl:call-template name="get-label"/>
  </xsl:variable>
  
  <!--@ generates arc ($prop) -->
  <xsl:element name="{$prop}">
   <!--@ generates typed node ($type) -->
   <xsl:element name="{$type}">
    <rdfs:label><xsl:value-of select="$name"/>
     <xsl:if test="$prop='dc:creator'">
      <xsl:variable name="sibl" select="following-sibling::*[1]"/>
      <xsl:choose>
       <xsl:when test="string-length($sibl) &gt; 27"> (<xsl:value-of select="substring($sibl,1,24)"/> ...)</xsl:when>
       <xsl:when test="$sibl != ''"> (<xsl:value-of select="$sibl"/>)</xsl:when>
      </xsl:choose>
     </xsl:if>
    </rdfs:label>
    <!--@ _experiment to give sameAs --><!--＠＠どうかな？-->
    <wm:sameNameAs>
     <xsl:attribute name="rdf:resource">http://www.kanzaki.com/ns/names/<xsl:choose>
      <xsl:when test="$prop='dc:creator' or $prop='dc:contributor'">agent</xsl:when>
      <xsl:otherwise><xsl:value-of select="substring-after($prop,':')"/></xsl:otherwise>
     </xsl:choose>/<xsl:value-of select="translate($name,' ','_')"/>#s</xsl:attribute>
     <xsl:attribute name="rdfs:label"><xsl:value-of select="$name"/></xsl:attribute>
    </wm:sameNameAs>
    <!--@ generates foaf:homepage (IFP) if child <a> element exists -->
    <!--＠＠次の2つはわざわざifpとしなくてもまとめられそう-->
    <xsl:if test="h:a/@href">
     <foaf:homepage rdf:resource="{h:a/@href}"/>
    </xsl:if>
    <xsl:if test="$a-type='ifp'">
     <foaf:homepage rdf:resource="{@href}"/>
    </xsl:if>
   </xsl:element>
  </xsl:element>
 </xsl:template>




 <xsl:template name="gen-class">
  <!--** Generates Class from schema prefixed name(s), recursively. ('.'を含む属性値からRDFのクラスを生成する) Steps: -->
  <xsl:param name="attrs"/><!--** value (list) to be the Class name. At least one token should contain prefixed name. -->
  <!--@ get one token from a list of space separated @class value (空白区切りの属性値リストから最初の1つを取り出して変数$cにセット) -->

  <xsl:variable name="c">
   <xsl:choose>
    <xsl:when test="contains($attrs,' ')">
     <xsl:value-of select="substring-before($attrs,' ')"/>
    </xsl:when>
    <xsl:otherwise>
     <xsl:value-of select="$attrs"/>
    </xsl:otherwise>
   </xsl:choose>
  </xsl:variable>
  <xsl:variable name="rest" select="substring-after($attrs,' ')"/>

  <xsl:choose>
   <!--@ find schema prefixed name.  ('.'を含む名前を選ぶ) Switch: -->
   <xsl:when test="contains($c,'.')">
    <!--@ _ case: if prefixed name found, generates a Class element as a child of foaf:topic, by calling gen-class-elt (foaf:topic要素の中にクラス要素を作るためにgen-class-eltを呼び出す): -->
    <foaf:topic>
     <xsl:call-template name="gen-class-elt">
      <xsl:with-param name="c" select="$c"/>
     </xsl:call-template>
    </foaf:topic>
   </xsl:when>
   <!--@ _otherwise, if more value(s) in @class list, then process them recursively (そうでなければ、2番目以降を引数に再起呼び出しを行う). -->
   <xsl:otherwise>
    <xsl:if test="$rest">
     <xsl:call-template name="gen-class">
      <xsl:with-param name="attrs" select="$rest"/>
     </xsl:call-template>
    </xsl:if>
   </xsl:otherwise>
  </xsl:choose>

 </xsl:template>



 <xsl:template name="gen-class-elt">
  <!--** generates appropriate typed node element from a schema prefixed name. (接頭辞つき名前から型付ノード要素を生成する) Steps: -->
  <xsl:param name="c"/>
  <!--@ find namespace by calling find-ns template (まず名前空間を解決). -->
  <xsl:variable name="ns">
   <xsl:call-template name="find-ns">
    <xsl:with-param name="pfx" select="substring-before($c,'.')"/>
   </xsl:call-template>
  </xsl:variable>
  <!--@ then generate a node by calling typed-or-untyped template (typed-or-untypedを呼んでノード要素を生成). Parameter 'elt' and 'ns' is passed depending on namespace.-->
  <xsl:call-template name="typed-or-untyped">
   <xsl:with-param name="elt">
    <xsl:choose>
     <xsl:when test="$ns=''">rdf:Description</xsl:when>
     <xsl:otherwise><xsl:value-of select="translate($c,'.',':')"/></xsl:otherwise>
    </xsl:choose>
   </xsl:with-param>
   <xsl:with-param name="ns">
    <xsl:choose>
     <xsl:when test="$ns=''">&rdfns;</xsl:when>
     <xsl:otherwise><xsl:value-of select="$ns"/></xsl:otherwise>
    </xsl:choose>
   </xsl:with-param>
  </xsl:call-template>
 </xsl:template>


 <xsl:template name="typed-or-untyped">
  <!--** generates typed or untyped node element, and processes child nodes. (名前空間が解決されていれば型付ノード要素を、そうでなければrdf:Descriptionを生成する) Steps: -->
  <xsl:param name="elt"/>
  <xsl:param name="ns"/>
  <!--@ generates a typed or untyped node element. -->
  <xsl:element name="{$elt}" namespace="{$ns}">
   <!--@ test if it can have a URI -->
   <xsl:call-template name="get-subject"/>
   <!--@ if @title|h2|h3 presents, add rdfs:label. -->
   <xsl:call-template name="find-title"/>
   <!--@ processes child elements to find properties for this node. -->
   <xsl:apply-templates select="&hinlineelt;"/>
   <xsl:apply-templates select="&hblockelt;"/>
   <!--
   <rdfs:comment>
    <xsl:value-of select="normalize-space(substring(.,1,40))"/>
   </rdfs:comment>
   -->
  </xsl:element>
 </xsl:template>
 

 <xsl:template name="get-subject">
  <!--** gives subject attribute or IFP (foaf:homepage) if appropriate id or URI presents. (適切なidあるいはURIがあれば、rdf:about、rdf:IDもしくはIFPとしてノードに与える) Steps: -->
  <xsl:choose>
   <!--@ case: calling node has @href, then use it as rdf:about. -->
   <!-- <a> calls proc-rel or proc-prop, then proc-prop-body, then gen-class-elt, then typed-or-untyped, which calls this template. looong way ! -->
   <xsl:when test="@href">
    <xsl:attribute name="rdf:about"><xsl:value-of select="@href"/></xsl:attribute>
   </xsl:when>

   <!--@ case: calling node has @id,  -->
   <xsl:when test="@id">
    <xsl:attribute name="rdf:ID">
     <xsl:choose>
     <!--@ _ if it has @class='sitemap:*', use @id as rdf:ID  -->
      <xsl:when test="starts-with(@class,'sitemap.')">
       <xsl:value-of select="@id"/>
      </xsl:when>
      <xsl:otherwise>
      <!--@ _ otherwese use '_topic_'+@id as rdf:ID, because XHTML @id cannot be the name of some real world object -->
       <xsl:value-of select="concat('_topic_',@id)"/>
      </xsl:otherwise>
     </xsl:choose>
    </xsl:attribute>
   </xsl:when>

   <!-- the rest will generally valid when calling node is a blocklevel element-->
   <!--@ case: a descendant a[@class='about'], then its @href is subject URI. Note @rel for this <a> is ignored by template a[@rel][@class='about'] (do nothing), otherwise this uri will be given both parent and child, generating undesirable result. -->
   <!-- a[@class='about']があれば主語URI。このとき@relがあっても無視する-->
   <xsl:when test=".//*[contains(@class,'about')][@href]">
    <xsl:attribute name="rdf:about"><xsl:value-of select=".//*[contains(@class,'about')]/@href"/></xsl:attribute>
    <rdfs:label><xsl:value-of select=".//*[contains(@class,'about')]"/></rdfs:label>
   </xsl:when>
   
   <!--@ case: a descendant img@class='about', then its @src is subject URI. -->
   <!-- 画像に@class='about'があれば主語URI-->
   <xsl:when test=".//*[contains(@class,'about')][@src]">
    <xsl:attribute name="rdf:about"><xsl:value-of select=".//*[contains(@class,'about')]/@src"/></xsl:attribute>
   </xsl:when>
   
   <!--@ case: a descendant a@class='ifp', then its @href is foaf:homepage. Good when the block element has @class='foaf.Organization'. DO NOT give any @rel for this <a> element, otherwise, it will generate duplicated foaf:homepage bothe for parent and <a> itself. -->
   <!-- a[@class='ifp']があれば、目的語のホームページURI。このとき、a[@class='about']とは違って@relは無視できないので、合わせて与えてはいけない -->
   <!-- Note this ifp will be achieved without this when cond, but just <a class='ifp' rel='foaf.topic'. However, this 'when' will generate more properties for the Class element, while @rel will make only its homepage property.-->
   <xsl:when test=".//*[contains(@class,'ifp')][@href]">
    <rdfs:label><xsl:value-of select=".//*[contains(@class,'ifp')]"/></rdfs:label>
    <foaf:homepage rdf:resource="{.//*[contains(@class,'ifp')]/@href}"/>
   </xsl:when>
  
  </xsl:choose>
 </xsl:template>
 

 <xsl:template name="find-ns">
  <!--** find appropriate namespace for an element (接頭辞から名前空間を調べる). Steps: -->
  <xsl:param name="pfx"/>
  <xsl:choose>
   <!--@ Try to find prefix:uri mapping from <link> elements in the source document. -->
   <xsl:when test="$schemas[@rel=concat('schema.',$pfx)]">
    <xsl:value-of select="$schemas[@rel=concat('schema.',$pfx)]/@href"/>
   </xsl:when>
   <!--@ or, if the prefix is used in this stylesheet (e.g. dc:, dct:, foaf:, wn:, etc.), use it. -->
   <xsl:when test="$myns[name()=$pfx]">
    <xsl:value-of select="$myns[name()=$pfx]"/>
   </xsl:when>
  </xsl:choose>
 </xsl:template>



 <xsl:template name="who">
  <!--** Processes metadata for the author (文書作者に関するメタデータをまとめて処理). Steps: -->
  <!--@ get author's mbox -->
  <xsl:variable name="mbox">
   <xsl:choose>
    <xsl:when test="h:link[@rev='made']"><xsl:value-of select="h:link[@rev='made']/@href"/></xsl:when>
    <xsl:when test="count(..//h:address//h:a[starts-with(@href,'mailto:')])=1"><xsl:value-of select="..//h:address//h:a[starts-with(@href,'mailto:')]/@href"/></xsl:when>
   </xsl:choose>
  </xsl:variable>
  <!--@ get author's name -->
  <xsl:variable name="foafname">
   <xsl:choose>
   <xsl:when test="h:meta[@name='author']">
    <xsl:value-of select="h:meta[@name='author']/@content"/>
   </xsl:when>
   <xsl:when test="h:meta[@name='dc.creator']">
    <xsl:value-of select="h:meta[@name='dc.creator']/@content"/>
   </xsl:when>
   <xsl:when test="$mbox='mailto:webmaster&#64;kanzaki.com'">KANZAKI, Masahide</xsl:when>
   </xsl:choose>
  </xsl:variable>
  <!--@ get author's foaf file location -->
  <xsl:variable name="foafloc">
   <xsl:choose>
    <xsl:when test="h:link[@rel='meta' and @title='FOAF']">
     <xsl:value-of select="h:link[@rel='meta' and @title='FOAF']/@href"/>
    </xsl:when>
    <xsl:when test="$mbox='mailto:webmaster&#64;kanzaki.com'">http://www.kanzaki.com/info/webwho.rdf</xsl:when>
   </xsl:choose>
  </xsl:variable>

  <!--@ if any info on the author found, then generate <foaf:maker> -->
  <xsl:variable name="who">
   <xsl:if test="not($mbox='')">
    <foaf:mbox rdf:resource="{$mbox}"/>
   </xsl:if>
   <xsl:if test="not($foafname='')">
    <foaf:name><xsl:value-of select="$foafname"/></foaf:name>
   </xsl:if>
   <xsl:if test="not($foafloc='')">
    <rdfs:seeAlso rdf:resource="{$foafloc}"/>
   </xsl:if>
   <xsl:apply-templates select="../h:body//h:*[@class='me']" mode="who"/>
  </xsl:variable>

  <xsl:if test="not($who='')">
   <foaf:maker>
    <!-- not necessarily a person -->
    <foaf:Agent rdf:nodeID="who">
     <xsl:copy-of select="$who"/>
    </foaf:Agent>
   </foaf:maker>
  </xsl:if>
  <!--
  <xsl:if test="h:meta[@name='ICBM']">
   <foaf:based_near rdf:parseType="Resource">
    <geo:lat><xsl:value-of select="substring-before(h:meta[@name='ICBM']/@content,',')"/></geo:lat>
    <geo:long><xsl:value-of select="substring-after(h:meta[@name='ICBM']/@content,',')"/></geo:long>
   </foaf:based_near>
  </xsl:if>
  -->
 </xsl:template>

 <xsl:template match="*">
  <!--** Do nothing for any unmatched element -->
 </xsl:template>


</xsl:stylesheet>
