<?xml version="1.0" encoding="utf-8" ?>
<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:h      ="http://www.w3.org/1999/xhtml"
  xmlns:ldrize ="http://purl.org/net/ldrize/ns#"
  >
  <xsl:output method="xml" encoding="UTF-8"/>

  <!-- XPath -->
  <xsl:variable name="structuredUriRegEx"
	select="/h:html/h:head/h:meta[@name='LDRize.structuredUriRegEx']/@content" />

  <xsl:variable name="article"><![CDATA[
	.//h:*[contains(concat(' ',normalize-space(@class),' '), ' hentry ')]
  ]]></xsl:variable>

  <xsl:variable name="link"><![CDATA[
	.//h:*[contains(concat(' ',normalize-space(@rel),' '), ' bookmark ')]
  ]]></xsl:variable>

  <xsl:variable name="view"><![CDATA[
	.//h:*[contains(concat(' ',normalize-space(@class),' '), ' entry-title ')]
  ]]></xsl:variable>

  <xsl:variable name="section"><![CDATA[
	.//div
  ]]></xsl:variable>

<!--
	// original SITEINFO
	name:      'hAtom 0.1',
	domain:    'microformats',
	paragraph: './/h:*[contains(concat(" ",normalize-space(@class)," "), " hentry ")]',
	link:      './/h:*[contains(@rel, "bookmark")]'
	view:      './/h:*[contains(concat(" ",normalize-space(@class)," "), " entry-title ")]//text()',
	-->
  
  <!-- 
	///////////////////////////////////////////////////////////////////////////
	end of settings
	///////////////////////////////////////////////////////////////////////////
	-->
  
  <xsl:variable name="about"
	select="//h:*[contains(concat(' ',normalize-space(@rel),' '), ' home ')]/@href" />

  <!-- show RDF -->
  <xsl:template match="/">
	<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:ldrize="http://purl.org/net/ldrize/ns#">
	  <rdf:Description>
		<xsl:call-template name="parse-about"/>
		<ldrize:hasStructure rdf:parseType="Resource">
		  <xsl:call-template name="parse-structuredUriRegEx"/>
		  <xsl:call-template name="parse-article"/>
		  <xsl:call-template name="parse-link"/>
		  <xsl:call-template name="parse-view"/>
		  <xsl:call-template name="parse-section"/>
		</ldrize:hasStructure>
	  </rdf:Description>
	</rdf:RDF>
  </xsl:template>
  
  <!-- about -->
  <xsl:template name="parse-about">
	<xsl:if test="$about">
	  <xsl:attribute name="rdf:about">
		<xsl:value-of select="$about"/>
	  </xsl:attribute>
	</xsl:if>
  </xsl:template>

	
  <!-- structuredUriRegEx -->
  <xsl:template name="parse-structuredUriRegEx">
	<xsl:if test="$structuredUriRegEx">
	  <xsl:element name="ldrize:structuredUriRegEx">
		<xsl:value-of select="$structuredUriRegEx"/>
	  </xsl:element>
	</xsl:if>
  </xsl:template>

  <!-- article -->
  <xsl:template name="parse-article">
	<xsl:if test="normalize-space($article)">
	  <ldrize:article><xsl:value-of select="normalize-space($article)"/></ldrize:article>
	</xsl:if>
  </xsl:template>

  <!-- link -->
  <xsl:template name="parse-link">
	<xsl:if test="normalize-space($link)">
	  <ldrize:link><xsl:value-of select="normalize-space($link)"/></ldrize:link>
	</xsl:if>
  </xsl:template>

  <!-- view -->
  <xsl:template name="parse-view">
	<xsl:if test="normalize-space($view)">
	  <ldrize:view><xsl:value-of select="normalize-space($view)"/></ldrize:view>
	</xsl:if>
  </xsl:template>

  <!-- section -->
  <xsl:template name="parse-section">
	<xsl:if test="normalize-space($section)">
	  <ldrize:section><xsl:value-of select="normalize-space($section)"/></ldrize:section>
	</xsl:if>
  </xsl:template>

</xsl:stylesheet>

<!--

 sample extracted RDF

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:ldrize="http://purl.org/net/ldrize/ns#">
  <rdf:Description rdf:about="http://white.s151.xrea.com/blog/">
	<ldrize:structuredUriRegEx>^http://white.s151.xrea.com/blog/</ldrize:structuredUriRegEx>
	<ldrize:article>//h:*[contains(concat(' ',normalize-space(@class),' '), ' hentry ')]</ldrize:article>
	<ldrize:link>//h:*[contains(concat(' ',normalize-space(@rel),' '), ' bookmark ')]</ldrize:link>
	<ldrize:view>//h:*[contains(concat(' ',normalize-space(@class),' '), ' entry-title ')]</ldrize:view>
  </rdf:Description>
</rdf:RDF>

-->
