<?xml version="1.0" encoding="Shift_JIS"?>
<xsl:stylesheet version="1.0"
	xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
	xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
	xmlns:rss="http://purl.org/rss/1.0/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:xht="http://www.w3.org/1999/xhtml"
	exclude-result-prefixes="xht"
>

<xsl:output
	method="xml"
	indent="yes"
	encoding="shift_jis"
/>

<xsl:template match="/child::xht:html">

<rdf:RDF>

	<rdf:Description
		xml:base="http://purl.org/jintrick/Personal/"
		rdf:about="index.html">

		<dc:title>Personnel</dc:title>
		<dc:description>広義のリンクについての考察サイト</dc:description>

		<rss:items>
			<rdf:Bag>
				<xsl:apply-templates select="descendant::xht:dl[1]" />
			</rdf:Bag>
		</rss:items>

	</rdf:Description>

</rdf:RDF>

</xsl:template>

<xsl:template match="xht:dl">

	<xsl:for-each select="child::xht:dt">
		<rdf:li>
			<rdf:Description>
				<dc:title><xsl:value-of select="string(self::*)" /></dc:title>
				<rss:items>

					<xsl:for-each select="following-sibling::xht:dd[position() = 1]">

						<xsl:for-each select="child::xht:ul | child::xht:ol | child::xht:dl">

							<xsl:if test="name() != 'dl'">
							
								<xsl:variable name="listType">
									<xsl:if test="name() = 'ul'"><xsl:value-of select="'rdf:Bag'" /></xsl:if>
									<xsl:if test="name() = 'ol'"><xsl:value-of select="'rdf:Seq'" /></xsl:if>
								</xsl:variable>

								<!-- rdf:Bag or rdf:Seq -->
								<xsl:element name="{$listType}">

									<xsl:for-each select="child::*">
										<xsl:choose>
											<xsl:when test="boolean(child::xht:dl) = true()">
												<xsl:apply-templates select="self::*" />
											</xsl:when>
											<xsl:otherwise>
												<rdf:li>
													<rdf:Description rdf:about="{child::xht:a/attribute::href}">
														<dc:title><xsl:value-of select="string(self::*)" /></dc:title>
													</rdf:Description>
												</rdf:li>
											</xsl:otherwise>
										</xsl:choose>
									</xsl:for-each>

								</xsl:element>

							</xsl:if>

							<xsl:if test="name() = 'dl'">
								<rdf:Bag>
									<xsl:apply-templates select="self::*" />
								</rdf:Bag>
							</xsl:if>

						</xsl:for-each>

					</xsl:for-each>

				</rss:items>
			</rdf:Description>
		</rdf:li>
	</xsl:for-each>

</xsl:template>

</xsl:stylesheet>


