[uf-discuss] RFC: Proposal for general purpose microformat

brian suda brian.suda at gmail.com
Fri Dec 2 08:37:04 PST 2005


Just be careful not to re-invent the wheel. The W3C has a recommended[1]
way to extract RDF from XHTML. This same idea can be applied for XML
(and just about anything else for that matter).

[1] - http://www.w3.org/TeamSubmission/grddl/


Abramo Bagnara wrote:

>Taken for granted that a microformat is a way to embed data inside xhtml
>presentation, last night I was wondering if really it was unavoidable to
>have so many different formats with complex rules and nasty exceptions.
>
>>From this thinking I've tried to develop a little proposal to embed
>arbitrary xml data inside xhtml and that may be extracted easily and
>without ambiguities while leaving total freedom on data presentation.
>
>My main interest was something similar to hcalendar to overcome current
>limitations of this microformat wrt params.
>
>This is the reason why you find that the attached test is for calendar
>data, but my proposal should be general enough to permit embedding of
>*any* xml data.
>
>The attached stylesheet is for extraction of data in xml form, but it
>might be easily modified to extract data in xCalendar or iCalendar
>format (that maps 1:1 to xml).
>
>  
>
>------------------------------------------------------------------------
>
><?xml version="1.0" encoding="ISO-8859-1"?>
><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
><html xmlns="http://www.w3.org/1999/xhtml">
>  <head>
>    <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
>    <title>Test</title>
>    <link type="text/css" rel="stylesheet" href="../../html/project.css" />
>  </head>
>  <body class="xx:vcalendar=">
>    <div class="xx:vtodo=">
>      <h2 class="xx:summary">Task di test</h2>
>      <div>
>        <span class="header">Location: </span>
>        <span class="xx:location">Location</span>
>      </div>
>      <div>
>        <b>Due date: </b>
>        <abbr class="xx:due=@title" title="20051130">30-11-2005</abbr>
>      </div>
>      <div class="xx:description">
>        <div class="ancestor-summary">Test</div>
>        <ol class="disc">
>          <li>
>            <div class="node-summary">
>              <a href="edit:/u/dothert/data/abramo/test.txt##18">Task di test</a>
>            </div>
>            <div class="node-location">Location</div>
>            <div class="node-description">
>              <p>Descrizione sotto divisa in paragrafi di una certa lunghezza di una
>certa lunghezza di una certa <b>lunghezza</b> di una certa lunghezza di una
>certa lunghezza di una certa lunghezza</p>
>              <p>Descrizione sotto divisa in paragrafi di una certa lunghezza di una
>certa lunghezza di una certa lunghezza di una certa lunghezza di una
>certa lunghezza di una certa lunghezza</p>
>              <p>Descrizione sotto divisa in paragrafi di una certa lunghezza di una
>certa lunghezza di una certa lunghezza di una certa lunghezza di una
>certa lunghezza di una certa lunghezza</p>
>            </div>
>          </li>
>        </ol>
>        <p>Descrizione della deadline</p>
>        <p>Descrizione sotto divisa in paragrafi di una certa lunghezza di una
>certa lunghezza di una certa lunghezza di una certa lunghezza di una
>certa lunghezza di una certa lunghezza</p>
>        <p>Descrizione sotto divisa in paragrafi di una certa lunghezza di una
>certa lunghezza di una certa lunghezza di una certa lunghezza di una
>certa lunghezza di una certa lunghezza</p>
>      </div>
>      <div><span class="header">Categories: </span><span class="xx:categories">a</span>, <span class="xx:categories">a:b</span>, <span class="xx:categories">a:b:c</span>, <span class="xx:categories">ismaele</span>, <span class="xx:categories">ismaele:opt</span>, <span class="xx:categories">licia</span>, <span class="xx:categories">licia:opt</span>, <span class="xx:categories">abramo</span>, <span class="xx:categories">abramo:cha</span>, <span class="xx:categories">test</span>, <span class="xx:categories">abramo</span></div>
>      <div>
>        <span class="header">Priority: </span>
>        <abbr class="xx:priority=@title" title="0">not specified</abbr>
>      </div>
>      <div>
>        <span class="header">Presidente: </span>
>        <span class="xx:attendee=">
>          <abbr class="xx:@role=@title" title="chair"></abbr>
>          <a class="xx:@cn xx:=@href" href="mailto:abramo.bagnara at gmail.com">Abramo Bagnara</a>
>        </span>
>      </div>
>      <div>
>	<span class="header">Partecipanti opzionali: </span>
>	<span class="xx:attendee=">
>	  <abbr class="xx:@role=@title" title="opt-participant"></abbr>
>          <a class="xx:@cn xx:=@href" href="mailto:">Ismaele Bagnara</a>
>        </span>, <span class="xx:attendee="><abbr class="xx:@role=@title"
>	title="opt-participant"></abbr>
>      <a class="xx:@cn xx:=@href" href="litabanelli at racine.ra.it">Licia Tabanelli</a></span></div>
>    </div>
>  </body>
></html>
>  
>
>------------------------------------------------------------------------
>
><?xml version="1.0"?>
><xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
>
><!--
><xsl:stylesheet version="1.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:dyn="http://exslt.org/dynamic"
>  extension-element-prefixes="dyn">
>-->
>
><!--
>  Extract xml embedded in xhtml.
>  First draft.
>
>  Copyright 2005 Abramo Bagnara <abramo.bagnara at gmail.com>
>-->
>
><xsl:output method="xml"
>  indent="yes"/>
>
><xsl:variable name="prefix" select="' xx:'"/>
>
><!--
><xsl:template name="dyn-evaluate">
>  <xsl:param name="xpath"/>
>  <xsl:for-each select="dyn:evaluate($xpath)">
>    <xsl:value-of select="."/>
>  </xsl:for-each>
></xsl:template>
>-->
>
><xsl:template name="dyn-evaluate">
>  <xsl:param name="xpath"/>
>  <xsl:choose>
>    <xsl:when test="$xpath='.//text()'">
>      <xsl:for-each select=".//text()">
>        <xsl:value-of select="."/>
>      </xsl:for-each>
>    </xsl:when>
>    <xsl:when test="$xpath='text()'">
>      <xsl:for-each select="text()">
>        <xsl:value-of select="."/>
>      </xsl:for-each>
>    </xsl:when>
>    <xsl:when test="starts-with($xpath,'@')">
>      <xsl:value-of select="@*[name()=substring($xpath,2)]"/>
>    </xsl:when>
>    <xsl:otherwise>
>      <xsl:for-each select="*[name()=$xpath]">
>        <xsl:value-of select="."/>
>      </xsl:for-each>
>    </xsl:otherwise>
>  </xsl:choose>
></xsl:template>
>
><xsl:template name="evaluate">
>  <xsl:param name="xpath"/>
>  <xsl:if test="$xpath != ''">
>    <xsl:call-template name="dyn-evaluate">
>      <xsl:with-param name="xpath" select="$xpath"/>
>    </xsl:call-template>
>  </xsl:if>
></xsl:template>
>
><!--
>class : destination
>      | destination '=' source
>      ;
>
>prefix : 'xx:' ;
>
>destination : name
>            | '@' name
>            ;
>
>source : ''
>       | xpath
>       ;
>-->
>
><xsl:template name="extract">
>  <xsl:param name="classes"/>
>  <xsl:variable name="c" select="substring-after(concat(' ',$classes),$prefix)"/>
>  <xsl:choose>
>    <xsl:when test="$c = ''">
>      <xsl:apply-templates/>
>    </xsl:when>
>    <xsl:otherwise>
>      <xsl:variable name="class" select="substring-before(concat($c,' '),' ')"/>
>      <xsl:variable name="destination" select="substring-before(concat($class,'='),'=')"/>
>      <xsl:variable name="source">
>        <xsl:choose>
>          <xsl:when test="contains($class,'=')">
>            <xsl:value-of select="substring-after($class,'=')"/>
>          </xsl:when>
>          <xsl:otherwise>.//text()</xsl:otherwise>
>        </xsl:choose>
>      </xsl:variable>
>      <xsl:choose>
>        <xsl:when test="$destination = ''">
>          <xsl:call-template name="evaluate">
>            <xsl:with-param name="xpath" select="$source"/>
>          </xsl:call-template>
>          <xsl:call-template name="extract">
>            <xsl:with-param name="classes" select="substring-after($c,' ')"/>
>          </xsl:call-template>
>        </xsl:when>
>        <xsl:when test="starts-with($destination,'@')">
>          <xsl:attribute name="{substring($destination,2)}">
>            <xsl:call-template name="evaluate">
>              <xsl:with-param name="xpath" select="$source"/>
>            </xsl:call-template>
>          </xsl:attribute>
>          <xsl:call-template name="extract">
>            <xsl:with-param name="classes" select="substring-after($c,' ')"/>
>          </xsl:call-template>
>        </xsl:when>
>        <xsl:otherwise>
>          <xsl:element name="{$destination}">
>            <xsl:call-template name="evaluate">
>              <xsl:with-param name="xpath" select="$source"/>
>            </xsl:call-template>
>            <xsl:call-template name="extract">
>              <xsl:with-param name="classes" select="substring-after($c,' ')"/>
>            </xsl:call-template>
>          </xsl:element>
>        </xsl:otherwise>
>      </xsl:choose>
>    </xsl:otherwise>
>  </xsl:choose>
></xsl:template>
>
><xsl:template match="*[@class]">
>  <xsl:call-template name="extract">
>    <xsl:with-param name="classes" select="@class"/>
>  </xsl:call-template>
></xsl:template>
>
><xsl:template match="text()"/>
>
></xsl:stylesheet>
>  
>
>------------------------------------------------------------------------
>
>_______________________________________________
>microformats-discuss mailing list
>microformats-discuss at microformats.org
>http://microformats.org/mailman/listinfo/microformats-discuss
>  
>



More information about the microformats-discuss mailing list