<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet href="http://www.w3.org/2002/02/style-xsl.css" type="text/css"?>

<xsl:stylesheet  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
 xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
 xmlns:wgi="http://www.w3.org/2002/10/scrape/wginfo#"
 xmlns:h="http://www.w3.org/1999/xhtml"
 xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
 xmlns:uri="http://www.w3.org/2000/07/uri43/uri.xsl?template="
 xmlns:conf="http://www.w3.org/2002/06/conf#"
 xmlns:org="http://www.w3.org/2001/04/roadmap/org#"
 xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
 xmlns:dc="http://purl.org/dc/elements/1.1/"
 xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
 xmlns:rss="http://purl.org/rss/1.0/"
 xmlns:mr="http://www.w3.org/2000/11/mr76/minutes#"
 xmlns:date="http://www.w3.org/2001/08/date-util.xslt"
 xmlns:hdr="http://www.w3.org/2001/11/http-head.xsl"
 xmlns:k="http://opencyc.sourceforge.net/daml/cyc.daml#"
 exclude-result-prefixes="date h hdr uri"
 version="1.0">

 <xsl:import href="http://www.w3.org/2000/07/uri43/uri.xsl"/>
 <xsl:import href="http://www.w3.org/2001/11/http-head.xsl"/>
 <xsl:import href="http://www.w3.org/2001/08/date-util.xslt"/>

 <xsl:include href="WG-drafts.xsl"/>
 <xsl:include href="WG-news.xsl"/>
 <xsl:include href="WG-meetings.xsl"/>
 <xsl:include href="WG-teleconferences.xsl"/>
 <xsl:include href="WG-deliverables.xsl"/>
 <xsl:include href="WG-participants.xsl"/>

 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
  <head>
   <title>Working Group Page to RDF XSLT</title>
  </head>
  <body>
   <div class="head"><a href="http://www.w3.org/"><img src="http://www.w3.org/Icons/w3c_home" alt="W3C" /></a></div>
   <h1>Working Group Page to RDF XSLT</h1>
   <p>Mark pages according to <a href="WG-Style-Guidelines.html">the guidelines</a> and check if the results are expected, hopefully a set of useful RDF.</p>
   <form method="get" action="/2000/06/webdata/xslt">
    <input type="hidden" name="xslfile" value="http://www.w3.org/2002/10/scrape/WGscrape.xsl" />
    URI of your page (needs Tidy prefix if not XHTML) <input type="text" name="xmlfile" value="http://cgi.w3.org/cgi-bin/tidy?docAddr=" /><br />
    Base URI (don't forget trailing slash) <input type="text" name="baseURI" value="Base URI of page" /><br />
    <input type="checkbox" name="auth" value="proxy" /><br />
    <input type="submit" />
   </form>
   <address>
    <a href="http://www.w3.org/People/ryanlee/">Ryan Lee</a> - Last modified: $Date: 2003/08/27 17:16:47 $, $Revision: 1.54 $
   </address>
  </body>
 </html>

 <xsl:output method="xml" encoding="iso-8859-1" indent="yes"/>
 <xsl:strip-space elements="*"/>

 <xsl:param name="baseURI"/>
 <xsl:param name="groupName"/>

 <xsl:variable name="anonID" select="concat($baseURI,'scrapedOverview.rdf','#thisGroup')"/>
 <xsl:variable name="tidy" select="'http://cgi.w3.org/cgi-bin/tidy-if?docAddr='"/>
 <xsl:variable name="wgProfile" select="'http://www.w3.org/2002/12/wg'"/>
 <xsl:variable name="defaultLang">
  <xsl:choose>
   <xsl:when test="/*[@xml:lang]">
    <xsl:value-of select="/*/@xml:lang"/>
   </xsl:when>
   <xsl:when test="/*[@lang]">
    <xsl:value-of select="/*/@lang"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="''"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:variable>

 <xsl:template match="/">
  <xsl:processing-instruction name="xml-stylesheet">href="http://www.w3.org/2002/10/scrape/wgi-to-html.xsl" type="application/xml"</xsl:processing-instruction>
  <xsl:processing-instruction name="xml-stylesheet">href="http://www.w3.org/2002/10/scrape/scraped-style.css" type="text/css"</xsl:processing-instruction>
  <xsl:if test="/h:html/h:head[not(@profile)]">
   <xsl:comment>This working group page is missing its profile attribute</xsl:comment>
  </xsl:if>
  <xsl:if test="/h:html/h:head[@profile] and not(starts-with(normalize-space(/h:html/h:head/@profile),concat($wgProfile,' ')) or (contains(normalize-space(/h:html/h:head/@profile),concat(' ',$wgProfile)) and string-length(substring-after(normalize-space(/h:html/h:head/@profile),concat(' ',$wgProfile)))=0) or contains(normalize-space(/h:html/h:head/@profile),concat(' ',$wgProfile,' ')) or normalize-space(/h:html/h:head/@profile)=$wgProfile)">
   <xsl:comment>This working group page is using the wrong profile attribute</xsl:comment>
  </xsl:if>
  <rdf:RDF>
   <xsl:attribute name="xml:lang">
    <xsl:value-of select="$defaultLang"/>
   </xsl:attribute>
   <rdf:Description rdf:about="{concat($baseURI,'scrapedOverview.rdf')}">
    <xsl:if test="$defaultLang!='en-US'">
     <xsl:attribute name="xml:lang">
      <xsl:value-of select="'en-US'"/>
     </xsl:attribute>
    </xsl:if>
    <dc:publisher>The World Wide Web Consortium (W3C)</dc:publisher>
    <dc:description>Generated by the automated Working Group XSL scraper</dc:description>
   </rdf:Description>
   <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('activity',' ')) or (contains(normalize-space(@class),concat(' ','activity')) and string-length(substring-after(normalize-space(@class),concat(' ','activity')))=0) or contains(normalize-space(@class),concat(' ','activity',' ')) or normalize-space(@class)='activity') or (starts-with(normalize-space(@rel),concat('activity',' ')) or (contains(normalize-space(@rel),concat(' ','activity')) and string-length(substring-after(normalize-space(@rel),concat(' ','activity')))=0) or contains(normalize-space(@rel),concat(' ','activity',' ')) or normalize-space(@rel)='activity')]">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('activity',' ')) or (contains(normalize-space(@class),concat(' ','activity')) and string-length(substring-after(normalize-space(@class),concat(' ','activity')))=0) or contains(normalize-space(@class),concat(' ','activity',' ')) or normalize-space(@class)='activity') or (starts-with(normalize-space(@rel),concat('activity',' ')) or (contains(normalize-space(@rel),concat(' ','activity')) and string-length(substring-after(normalize-space(@rel),concat(' ','activity')))=0) or contains(normalize-space(@rel),concat(' ','activity',' ')) or normalize-space(@rel)='activity')]" mode="general"/>
   </xsl:if>
   <org:WorkingGroup>
    <xsl:attribute name="rdf:about">
     <xsl:value-of select="$anonID"/>
    </xsl:attribute>
    <org:name>
     <xsl:choose>
      <xsl:when test="string-length($groupName)!=0">
       <xsl:value-of select="normalize-space($groupName)"/>
      </xsl:when>
      <xsl:otherwise>
       <xsl:apply-templates select="h:html/h:head/h:title" mode="format"/>
      </xsl:otherwise>
     </xsl:choose>
    </org:name>
    <contact:homePage rdf:resource="{$baseURI}"/>
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@rel),concat('charter',' ')) or (contains(normalize-space(@rel),concat(' ','charter')) and string-length(substring-after(normalize-space(@rel),concat(' ','charter')))=0) or contains(normalize-space(@rel),concat(' ','charter',' ')) or normalize-space(@rel)='charter')]" mode="general"/>
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('summary',' ')) or (contains(normalize-space(@class),concat(' ','summary')) and string-length(substring-after(normalize-space(@class),concat(' ','summary')))=0) or contains(normalize-space(@class),concat(' ','summary',' ')) or normalize-space(@class)='summary')]" mode="general"/>
    <!-- PLUGIN general group characteristic above as apply-template -->
    <!-- PLUGIN information class below as @rel -->
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@rel),concat('news',' ')) or (contains(normalize-space(@rel),concat(' ','news')) and string-length(substring-after(normalize-space(@rel),concat(' ','news')))=0) or contains(normalize-space(@rel),concat(' ','news',' ')) or normalize-space(@rel)='news') or (starts-with(normalize-space(@rel),concat('meetings',' ')) or (contains(normalize-space(@rel),concat(' ','meetings')) and string-length(substring-after(normalize-space(@rel),concat(' ','meetings')))=0) or contains(normalize-space(@rel),concat(' ','meetings',' ')) or normalize-space(@rel)='meetings') or (starts-with(normalize-space(@rel),concat('teleconferences',' ')) or (contains(normalize-space(@rel),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@rel),concat(' ','teleconferences')))=0) or contains(normalize-space(@rel),concat(' ','teleconferences',' ')) or normalize-space(@rel)='teleconferences') or (starts-with(normalize-space(@rel),concat('deliverables',' ')) or (contains(normalize-space(@rel),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@rel),concat(' ','deliverables')))=0) or contains(normalize-space(@rel),concat(' ','deliverables',' ')) or normalize-space(@rel)='deliverables') or (starts-with(normalize-space(@rel),concat('participants',' ')) or (contains(normalize-space(@rel),concat(' ','participants')) and string-length(substring-after(normalize-space(@rel),concat(' ','participants')))=0) or contains(normalize-space(@rel),concat(' ','participants',' ')) or normalize-space(@rel)='participants') or (starts-with(normalize-space(@rel),concat('drafts',' ')) or (contains(normalize-space(@rel),concat(' ','drafts')) and string-length(substring-after(normalize-space(@rel),concat(' ','drafts')))=0) or contains(normalize-space(@rel),concat(' ','drafts',' ')) or normalize-space(@rel)='drafts')]" mode="external"/>
    <!-- this had to be repeated for document() references -->
    <!-- but it allows every grouping to be made correctly -->
    <!-- PLUGIN below information class                    -->
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]">
     <wgi:hasNews rdf:parseType="Collection">
      <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]|//h:ol[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]|//h:dl[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]|//h:div[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]" mode="news"/>
     </wgi:hasNews>
    </xsl:if>
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]">
     <wgi:hasMeetings rdf:parseType="Collection">
      <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]|//h:ol[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]|//h:dl[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]|//h:div[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]|//h:table[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]" mode="meetings"/>
     </wgi:hasMeetings>
    </xsl:if>
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]">
     <wgi:hasTeleconferences rdf:parseType="Collection">
      <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]|//h:ol[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]|//h:dl[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]|//h:div[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]|//h:table[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]" mode="teleconferences"/>
     </wgi:hasTeleconferences>
    </xsl:if>
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]">
     <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]|//h:ol[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]|//h:dl[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]|//h:div[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]|//h:table[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]" mode="deliverables"/>
    </xsl:if>
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]">
     <wgi:hasParticipants rdf:parseType="Collection">
      <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]|//h:ol[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]|//h:dl[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]|//h:div[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]|//h:table[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]" mode="participants"/>
     </wgi:hasParticipants>
    </xsl:if>
    <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]">
     <wgi:hasDrafts rdf:parseType="Collection">
      <xsl:apply-templates select="//h:ul[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]|//h:ol[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]|//h:dl[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]|//h:div[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]|//h:table[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]" mode="drafts"/>
     </wgi:hasDrafts>
    </xsl:if>
    <xsl:apply-templates select="." mode="advanced"/>
   </org:WorkingGroup>
  </rdf:RDF>
 </xsl:template>

 <!-- GENERAL GROUP CHARACTERISTICS -->
 <xsl:template match="h:*[(starts-with(normalize-space(@class),concat('activity',' ')) or (contains(normalize-space(@class),concat(' ','activity')) and string-length(substring-after(normalize-space(@class),concat(' ','activity')))=0) or contains(normalize-space(@class),concat(' ','activity',' ')) or normalize-space(@class)='activity') or (starts-with(normalize-space(@rel),concat('activity',' ')) or (contains(normalize-space(@rel),concat(' ','activity')) and string-length(substring-after(normalize-space(@rel),concat(' ','activity')))=0) or contains(normalize-space(@rel),concat(' ','activity',' ')) or normalize-space(@rel)='activity')]" mode="general">
  <org:Activity>
   <xsl:if test="@href">
    <contact:homePage>
     <xsl:attribute name="rdf:resource">
      <xsl:apply-templates select="@href"/>
     </xsl:attribute>
    </contact:homePage>
   </xsl:if>
   <xsl:if test="@class">
    <org:name><xsl:apply-templates select="." mode="format"/></org:name>
   </xsl:if>
   <org:includes rdf:resource="{$anonID}"/>
  </org:Activity>
 </xsl:template>

 <xsl:template match="h:*[(starts-with(normalize-space(@rel),concat('charter',' ')) or (contains(normalize-space(@rel),concat(' ','charter')) and string-length(substring-after(normalize-space(@rel),concat(' ','charter')))=0) or contains(normalize-space(@rel),concat(' ','charter',' ')) or normalize-space(@rel)='charter')]" mode="general">
  <org:charter>
   <doc:Work>
    <xsl:attribute name="rdf:about">
     <xsl:apply-templates select="@href"/>
    </xsl:attribute>
   </doc:Work>
  </org:charter>
 </xsl:template>

 <xsl:template match="h:*[(starts-with(normalize-space(@class),concat('summary',' ')) or (contains(normalize-space(@class),concat(' ','summary')) and string-length(substring-after(normalize-space(@class),concat(' ','summary')))=0) or contains(normalize-space(@class),concat(' ','summary',' ')) or normalize-space(@class)='summary')]" mode="general">
  <dc:description>
   <xsl:apply-templates select="." mode="format"/>
  </dc:description>
 </xsl:template>

 <!-- EXTERNAL -->
 <!-- PLUGIN information class below as @rel -->
 <xsl:template match="h:*[(starts-with(normalize-space(@rel),concat('news',' ')) or (contains(normalize-space(@rel),concat(' ','news')) and string-length(substring-after(normalize-space(@rel),concat(' ','news')))=0) or contains(normalize-space(@rel),concat(' ','news',' ')) or normalize-space(@rel)='news') or (starts-with(normalize-space(@rel),concat('meetings',' ')) or (contains(normalize-space(@rel),concat(' ','meetings')) and string-length(substring-after(normalize-space(@rel),concat(' ','meetings')))=0) or contains(normalize-space(@rel),concat(' ','meetings',' ')) or normalize-space(@rel)='meetings') or (starts-with(normalize-space(@rel),concat('teleconferences',' ')) or (contains(normalize-space(@rel),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@rel),concat(' ','teleconferences')))=0) or contains(normalize-space(@rel),concat(' ','teleconferences',' ')) or normalize-space(@rel)='teleconferences') or (starts-with(normalize-space(@rel),concat('deliverables',' ')) or (contains(normalize-space(@rel),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@rel),concat(' ','deliverables')))=0) or contains(normalize-space(@rel),concat(' ','deliverables',' ')) or normalize-space(@rel)='deliverables') or (starts-with(normalize-space(@rel),concat('participants',' ')) or (contains(normalize-space(@rel),concat(' ','participants')) and string-length(substring-after(normalize-space(@rel),concat(' ','participants')))=0) or contains(normalize-space(@rel),concat(' ','participants',' ')) or normalize-space(@rel)='participants') or (starts-with(normalize-space(@rel),concat('drafts',' ')) or (contains(normalize-space(@rel),concat(' ','drafts')) and string-length(substring-after(normalize-space(@rel),concat(' ','drafts')))=0) or contains(normalize-space(@rel),concat(' ','drafts',' ')) or normalize-space(@rel)='drafts')]" mode="external">
  <xsl:variable name="resuri">
   <xsl:apply-templates select="@href"/>
  </xsl:variable>
  <xsl:variable name="doc" select="document(concat($tidy,$resuri))"/>
<!--  <xsl:variable name="doc" select="document($resuri)"/>-->
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]">
   <wgi:hasNews rdf:parseType="Collection">
    <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('news',' ')) or (contains(normalize-space(@class),concat(' ','news')) and string-length(substring-after(normalize-space(@class),concat(' ','news')))=0) or contains(normalize-space(@class),concat(' ','news',' ')) or normalize-space(@class)='news')]" mode="news">
     <xsl:with-param name="externalURI" select="$resuri"/>
    </xsl:apply-templates>
   </wgi:hasNews>
  </xsl:if>
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]">
   <wgi:hasMeetings rdf:parseType="Collection">
    <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('meetings',' ')) or (contains(normalize-space(@class),concat(' ','meetings')) and string-length(substring-after(normalize-space(@class),concat(' ','meetings')))=0) or contains(normalize-space(@class),concat(' ','meetings',' ')) or normalize-space(@class)='meetings')]" mode="meetings">
     <xsl:with-param name="externalURI" select="$resuri"/>
    </xsl:apply-templates>
   </wgi:hasMeetings>
  </xsl:if>
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]">
   <wgi:hasTeleconferences rdf:parseType="Collection">
    <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('teleconferences',' ')) or (contains(normalize-space(@class),concat(' ','teleconferences')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconferences')))=0) or contains(normalize-space(@class),concat(' ','teleconferences',' ')) or normalize-space(@class)='teleconferences')]" mode="teleconferences">
     <xsl:with-param name="externalURI" select="$resuri"/>
    </xsl:apply-templates>
   </wgi:hasTeleconferences>
  </xsl:if>
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]">
   <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('deliverables',' ')) or (contains(normalize-space(@class),concat(' ','deliverables')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverables')))=0) or contains(normalize-space(@class),concat(' ','deliverables',' ')) or normalize-space(@class)='deliverables')]" mode="deliverables">
    <xsl:with-param name="externalURI" select="$resuri"/>
   </xsl:apply-templates>
  </xsl:if>
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]">
   <wgi:hasParticipants rdf:parseType="Collection">
    <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('participants',' ')) or (contains(normalize-space(@class),concat(' ','participants')) and string-length(substring-after(normalize-space(@class),concat(' ','participants')))=0) or contains(normalize-space(@class),concat(' ','participants',' ')) or normalize-space(@class)='participants')]" mode="participants">
     <xsl:with-param name="externalURI" select="$resuri"/>
    </xsl:apply-templates>
   </wgi:hasParticipants>
  </xsl:if>
  <xsl:if test="$doc//h:*[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]">
   <wgi:hasDrafts rdf:parseType="Collection">
    <xsl:apply-templates select="$doc//h:*[(starts-with(normalize-space(@class),concat('drafts',' ')) or (contains(normalize-space(@class),concat(' ','drafts')) and string-length(substring-after(normalize-space(@class),concat(' ','drafts')))=0) or contains(normalize-space(@class),concat(' ','drafts',' ')) or normalize-space(@class)='drafts')]" mode="drafts">
     <xsl:with-param name="externalURI" select="$resuri"/>
    </xsl:apply-templates>
   </wgi:hasDrafts>
  </xsl:if>
  <xsl:apply-templates select="document(concat($tidy,$resuri))" mode="advanced">
<!--  <xsl:apply-templates select="document($resuri)" mode="advanced">-->
   <xsl:with-param name="externalURI" select="$resuri"/>
  </xsl:apply-templates>
 </xsl:template>

 <!-- DISPATCHING ADVANCED -->
 <xsl:template match="*" mode="advanced">
  <xsl:param name="externalURI"/>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('item',' ')) or (contains(normalize-space(@class),concat(' ','item')) and string-length(substring-after(normalize-space(@class),concat(' ','item')))=0) or contains(normalize-space(@class),concat(' ','item',' ')) or normalize-space(@class)='item')]">
   <wgi:hasNews rdf:parseType="Collection">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('item',' ')) or (contains(normalize-space(@class),concat(' ','item')) and string-length(substring-after(normalize-space(@class),concat(' ','item')))=0) or contains(normalize-space(@class),concat(' ','item',' ')) or normalize-space(@class)='item')]" mode="newsAdvanced">
     <xsl:with-param name="externalURI" select="$externalURI"/>
    </xsl:apply-templates>
   </wgi:hasNews>
  </xsl:if>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('draft',' ')) or (contains(normalize-space(@class),concat(' ','draft')) and string-length(substring-after(normalize-space(@class),concat(' ','draft')))=0) or contains(normalize-space(@class),concat(' ','draft',' ')) or normalize-space(@class)='draft')]">
   <wgi:hasDrafts rdf:parseType="Collection">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('draft',' ')) or (contains(normalize-space(@class),concat(' ','draft')) and string-length(substring-after(normalize-space(@class),concat(' ','draft')))=0) or contains(normalize-space(@class),concat(' ','draft',' ')) or normalize-space(@class)='draft')]" mode="draftAdvanced">
     <xsl:with-param name="externalURI" select="$externalURI"/>
    </xsl:apply-templates>
   </wgi:hasDrafts>
  </xsl:if>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('deliverable',' ')) or (contains(normalize-space(@class),concat(' ','deliverable')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverable')))=0) or contains(normalize-space(@class),concat(' ','deliverable',' ')) or normalize-space(@class)='deliverable')]">
   <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('deliverable',' ')) or (contains(normalize-space(@class),concat(' ','deliverable')) and string-length(substring-after(normalize-space(@class),concat(' ','deliverable')))=0) or contains(normalize-space(@class),concat(' ','deliverable',' ')) or normalize-space(@class)='deliverable')]" mode="deliverableAdvanced">
    <xsl:with-param name="externalURI" select="$externalURI"/>
   </xsl:apply-templates>
  </xsl:if>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('meeting',' ')) or (contains(normalize-space(@class),concat(' ','meeting')) and string-length(substring-after(normalize-space(@class),concat(' ','meeting')))=0) or contains(normalize-space(@class),concat(' ','meeting',' ')) or normalize-space(@class)='meeting')]">
   <wgi:hasMeetings rdf:parseType="Collection">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('meeting',' ')) or (contains(normalize-space(@class),concat(' ','meeting')) and string-length(substring-after(normalize-space(@class),concat(' ','meeting')))=0) or contains(normalize-space(@class),concat(' ','meeting',' ')) or normalize-space(@class)='meeting')]" mode="meetingAdvanced">
     <xsl:with-param name="externalURI" select="$externalURI"/>
    </xsl:apply-templates>
   </wgi:hasMeetings>
  </xsl:if>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('teleconference',' ')) or (contains(normalize-space(@class),concat(' ','teleconference')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconference')))=0) or contains(normalize-space(@class),concat(' ','teleconference',' ')) or normalize-space(@class)='teleconference')]">
   <wgi:hasTeleconferences rdf:parseType="Collection">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('teleconference',' ')) or (contains(normalize-space(@class),concat(' ','teleconference')) and string-length(substring-after(normalize-space(@class),concat(' ','teleconference')))=0) or contains(normalize-space(@class),concat(' ','teleconference',' ')) or normalize-space(@class)='teleconference')]" mode="teleconferenceAdvanced">
     <xsl:with-param name="externalURI" select="$externalURI"/>
    </xsl:apply-templates>
   </wgi:hasTeleconferences>
  </xsl:if>
  <xsl:if test="//h:*[(starts-with(normalize-space(@class),concat('participant',' ')) or (contains(normalize-space(@class),concat(' ','participant')) and string-length(substring-after(normalize-space(@class),concat(' ','participant')))=0) or contains(normalize-space(@class),concat(' ','participant',' ')) or normalize-space(@class)='participant')]">
   <!-- participants -->
   <wgi:hasParticipants rdf:parseType="Collection">
    <xsl:apply-templates select="//h:*[(starts-with(normalize-space(@class),concat('participant',' ')) or (contains(normalize-space(@class),concat(' ','participant')) and string-length(substring-after(normalize-space(@class),concat(' ','participant')))=0) or contains(normalize-space(@class),concat(' ','participant',' ')) or normalize-space(@class)='participant')]" mode="participantAdvanced">
     <xsl:with-param name="externalURI" select="$externalURI"/>
    </xsl:apply-templates>
   </wgi:hasParticipants>
  </xsl:if>
  <!-- PLUGIN information class above as when -->
 </xsl:template>

 <!-- cute trick to expand all URIs to absolute -->
 <!-- thanks to Bert                            -->
 <xsl:template match="@src|@href">
  <xsl:param name="externalURI"/>
  <xsl:choose>
   <xsl:when test="string-length(normalize-space($externalURI))!=0">
    <xsl:call-template name="uri:expand">
     <xsl:with-param name="base" select="$externalURI"/>
     <xsl:with-param name="there" select="."/>
    </xsl:call-template>
   </xsl:when>
   <xsl:otherwise>
    <xsl:call-template name="uri:expand">
     <xsl:with-param name="base" select="$baseURI"/>
     <xsl:with-param name="there" select="."/>
    </xsl:call-template>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <!-- parse out a date range if it might exist  -->
 <!-- currently only called by meetings/telecon -->
 <xsl:template name="parse-maybe-date-range">
  <xsl:param name="guessDateRange"/>
  <xsl:param name="otherwiseElt"/>
  <xsl:choose>
   <!-- like 3-4 March 2003 / 3-4 Mar 2003 or similar -->
   <xsl:when test="contains($guessDateRange,'-') and contains($guessDateRange,' ') and number(substring-before($guessDateRange,'-'))=number(substring-before($guessDateRange,'-')) and number(substring-before(substring-after($guessDateRange,'-'),' '))=number(substring-before(substring-after($guessDateRange,'-'),' ')) and number(substring-after(substring-after($guessDateRange,' '),' '))=number(substring-after(substring-after($guessDateRange,' '),' '))">
    <xsl:if test="string-length(substring-before(substring-after($guessDateRange,' '),' '))=3">
     <k:startingDate>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after($guessDateRange,' '),' '),' ',substring-before($guessDateRange,'-'),' ',substring-after(substring-after($guessDateRange,' '),' '))"/>
      </xsl:call-template>
     </k:startingDate>
     <k:endingDate>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after($guessDateRange,' '),' '),' ',substring-before(substring-after($guessDateRange,'-'),' '),' ',substring-after(substring-after($guessDateRange,' '),' '))"/>
      </xsl:call-template>
     </k:endingDate>
    </xsl:if>
    <xsl:if test="string-length(substring-before(substring-after($guessDateRange,' '),' '))&gt;3">
     <k:startingDate>
      <xsl:call-template name="date:makeDateNumeric">
       <xsl:with-param name="friendlyDate" select="concat(substring-before($guessDateRange,'-'),' ',substring-after($guessDateRange,' '))"/>
       <xsl:with-param name="format-iso" select="'t'"/>
      </xsl:call-template>      
     </k:startingDate>
     <k:endingDate>
      <xsl:call-template name="date:makeDateNumeric">
       <xsl:with-param name="friendlyDate" select="substring-after($guessDateRange,'-')"/>
       <xsl:with-param name="format-iso" select="'t'"/>
      </xsl:call-template>
     </k:endingDate>
    </xsl:if>
   </xsl:when>
   <!-- like 28 February - 3 March 2003 / 28 Feb - 3 Mar 2003 or similar -->
   <xsl:when test="contains($guessDateRange,'-') and contains($guessDateRange,' ') and contains(normalize-space(substring-before($guessDateRange,'-')),' ') and number(substring-before(normalize-space(substring-before($guessDateRange,'-')),' '))=number(substring-before(normalize-space(substring-before($guessDateRange,'-')),' ')) and number(substring-before(normalize-space(substring-after($guessDateRange,'-')),' '))=number(substring-before(normalize-space(substring-after($guessDateRange,'-')),' '))">
    <xsl:choose>
     <xsl:when test="string-length(substring-after(normalize-space(substring-before($guessDateRange,'-')),' '))=3 and string-length(substring-before(substring-after(normalize-space(substring-after($guessDateRange,'-')),' '),' '))=3">
     <k:startingDate>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-after(normalize-space(substring-before($guessDateRange,'-')),' '),' ',substring-before(normalize-space(substring-before($guessDateRange,'-')),' '),' ',substring-after(substring-after(normalize-space(substring-after($guessDateRange,'-')),' '),' '))"/>
      </xsl:call-template>
     </k:startingDate>
     <k:endingDate>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after(normalize-space(substring-after($guessDateRange,'-')),' '),' '),' ',substring-before(normalize-space(substring-after($guessDateRange,'-')),' '),' ',substring-after(substring-after(normalize-space(substring-after($guessDateRange,'-')),' '),' '))"/>
      </xsl:call-template>
     </k:endingDate>
     </xsl:when>
     <xsl:otherwise>
     <k:startingDate>
      <xsl:call-template name="date:makeDateNumeric">
       <xsl:with-param name="friendlyDate" select="concat(normalize-space(substring-before($guessDateRange,'-')),' ',substring-after(substring-after(normalize-space(substring-after($guessDateRange,'-')),' '),' '))"/>
       <xsl:with-param name="format-iso" select="'t'"/>
      </xsl:call-template>      
     </k:startingDate>
     <k:endingDate>
      <xsl:call-template name="date:makeDateNumeric">
       <xsl:with-param name="friendlyDate" select="normalize-space(substring-after($guessDateRange,'-'))"/>
       <xsl:with-param name="format-iso" select="'t'"/>
      </xsl:call-template>
     </k:endingDate>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <!-- like 2003-02-28 to 2003-03-03 -->
   <xsl:when test="contains($guessDateRange,'-') and contains($guessDateRange,' ') and contains($guessDateRange,' to ') and string-length(substring-before($guessDateRange,' '))=10">
    <k:startingDate>
     <xsl:value-of select="substring($guessDateRange,1,10)"/>
    </k:startingDate>
    <k:endingDate>
     <xsl:value-of select="substring($guessDateRange,15,10)"/>
    </k:endingDate>
   </xsl:when>
   <xsl:otherwise>
    <xsl:choose>
     <xsl:when test="$otherwiseElt='conf:start'">
      <conf:start>
       <xsl:call-template name="parse-date">
        <xsl:with-param name="guessDate" select="$guessDateRange"/>
       </xsl:call-template>
      </conf:start>
     </xsl:when>
     <xsl:when test="$otherwiseElt='mr:date'">
      <mr:date>
       <xsl:call-template name="parse-date">
        <xsl:with-param name="guessDate" select="$guessDateRange"/>
       </xsl:call-template>
      </mr:date>
     </xsl:when>
     <xsl:otherwise>
      <dc:date>
       <xsl:call-template name="parse-date">
        <xsl:with-param name="guessDate" select="$guessDateRange"/>
       </xsl:call-template>
      </dc:date>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <!-- date parsing, for only a few good formats          -->
 <!-- recognizes these formats only, spews back whatever -->
 <!-- junk it was handed if not                          -->
 <!-- Da, DD Mon CCYY HH24:MI:SS Z                -->
 <!-- CCYY-MM-DD     -->
 <!-- DD Month CCYY  -->
 <!-- CCYY-MM        -->
 <!-- YYYYMMDD (often returned from date: stuff)  -->
 <!-- DD Mon 'YY     -->
 <!-- Mon 'YY        -->
 <xsl:template name="parse-date">
  <xsl:param name="guessDate"/>
  <xsl:choose>
   <!-- check first format -->
   <xsl:when test="contains($guessDate,',') and contains($guessDate,':')">
    <xsl:variable name="date" select="concat(substring($guessDate,9,3),' ',substring($guessDate,6,2),' ',substring($guessDate,13,4))"/>
    <xsl:call-template name="date:makeAbbrDateNumeric">
     <xsl:with-param name="abbrDate" select="$date"/>
    </xsl:call-template>
   </xsl:when>
   <!-- check ISO formats -->
   <!-- YYYY-MM-DD -->
   <!-- YYYY-MM    -->
   <xsl:when test="contains($guessDate,'-')">
    <xsl:choose>
     <xsl:when test="string-length(substring-before($guessDate,'-'))=4 and number(substring-before($guessDate,'-'))=number(substring-before($guessDate,'-')) and string-length(substring-after($guessDate,'-'))=5">
      <xsl:value-of select="normalize-space($guessDate)"/>
     </xsl:when>
     <xsl:when test="string-length(substring-before($guessDate,'-'))=4 and number(substring-before($guessDate,'-'))=number(substring-before($guessDate,'-')) and string-length(substring-after($guessDate,'-'))=2">
      <xsl:value-of select="normalize-space($guessDate)"/>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="normalize-space($guessDate)"/>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <!-- DD Mon 'YY -->
   <!-- Mon 'YY -->
   <xsl:when test='contains($guessDate,"&apos;")'>
    <xsl:choose>
     <!-- Mon 'YY -->
     <xsl:when test="string-length(substring-before($guessDate,' '))=3">
      <xsl:variable name="year">
       <xsl:if test='starts-with(substring-after($guessDate,"&apos;"),"9")'>
        <xsl:value-of select='concat("19",substring-after($guessDate,"&apos;"))'/>
       </xsl:if>
       <xsl:if test='starts-with(substring-after($guessDate,"&apos;"),"0")'>
        <xsl:value-of select='concat("20",substring-after($guessDate,"&apos;"))'/>
       </xsl:if>
      </xsl:variable>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after($guessDate,' '),' '),' 01 ',$year)"/>
      </xsl:call-template>
     </xsl:when>
     <!-- DD Mon 'YY -->
     <xsl:when test="number(substring($guessDate,1,1))=number(substring($guessDate,1,1)) and string-length(substring-before($guessDate,' '))&lt;=2">
      <xsl:variable name="year">
       <xsl:if test='starts-with(substring-after($guessDate,"&apos;"),"9")'>
        <xsl:value-of select='concat("19",substring-after($guessDate,"&apos;"))'/>
       </xsl:if>
       <xsl:if test='starts-with(substring-after($guessDate,"&apos;"),"0")'>
        <xsl:value-of select='concat("20",substring-after($guessDate,"&apos;"))'/>
       </xsl:if>
      </xsl:variable>
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after($guessDate,' '),' '),' ',format-number(number(substring-before($guessDate,' ')),'00'),' ',$year)"/>
      </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="normalize-space($guessDate)"/>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <!-- DD Month CCYY or DD Mon CCYY or Month CCYY -->
   <xsl:when test="contains($guessDate,' ') and not(contains($guessDate,',')) and not(contains($guessDate,':'))">
    <xsl:choose>
     <!-- Month CCYY -->
     <xsl:when test="number(substring-after($guessDate,' '))=number(substring-after($guessDate,' ')) and string-length(substring-after($guessDate,' '))=4 and not(contains(substring-before($guessDate,' '),' ')) and string-length(substring-before($guessDate,' '))&gt;3">
      <xsl:variable name="cheatdate">
       <xsl:call-template name="date:makeDateNumeric">
        <xsl:with-param name="friendlyDate" select="concat('01 ',$guessDate)"/>
        <xsl:with-param name="format-iso" select="'t'"/>
       </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="substring($cheatdate,1,7)"/>
     </xsl:when>
     <!-- Mon CCYY -->
     <xsl:when test="number(substring-after($guessDate,' '))=number(substring-after($guessDate,' ')) and string-length(substring-after($guessDate,' '))=4 and not(contains(substring-after($guessDate,' '),' ')) and string-length(substring-before($guessDate,' '))=3">
      <xsl:variable name="cheatdate">
       <xsl:call-template name="date:makeAbbrDateNumeric">
        <xsl:with-param name="abbrDate" select="concat(substring-before($guessDate,' '),' 01 ',substring-after($guessDate,' '))"/>
       </xsl:call-template>
      </xsl:variable>
      <xsl:value-of select="substring($cheatdate,1,7)"/>
     </xsl:when>
     <!-- DDnd Month CCYY -->
     <xsl:when test="((number(substring($guessDate,1,1))=number(substring($guessDate,1,1)) and string-length(substring-before($guessDate,' '))=3) or (number(substring($guessDate,1,2))=number(substring($guessDate,1,2)) and string-length(substring-before($guessDate,' '))=4)) and number(substring-after(substring-after($guessDate,' '),' '))=number(substring-after(substring-after($guessDate,' '),' ')) and string-length(substring-after(substring-after($guessDate,' '),' '))=4 and string-length(substring-before(substring-after($guessDate,' '),' '))&gt;3">
      <xsl:if test="string-length(substring-before($guessDate,' '))=4">
       <xsl:call-template name="date:makeDateNumeric">
        <xsl:with-param name="friendlyDate" select="concat(substring($guessDate,1,2),' ',substring($guessDate,6))"/>
        <xsl:with-param name="format-iso" select="'t'"/>
       </xsl:call-template>
      </xsl:if>
      <xsl:if test="string-length(substring-before($guessDate,' '))=3">
       <xsl:call-template name="date:makeDateNumeric">
        <xsl:with-param name="friendlyDate" select="concat(substring($guessDate,1,1),' ',substring($guessDate,5))"/>
        <xsl:with-param name="format-iso" select="'t'"/>
       </xsl:call-template>
      </xsl:if>
     </xsl:when>
     <!-- DDnd Mon CCYY -->
     <xsl:when test="((number(substring($guessDate,1,1))=number(substring($guessDate,1,1)) and string-length(substring-before($guessDate,' '))=3) or (number(substring($guessDate,1,2))=number(substring($guessDate,1,2)) and string-length(substring-before($guessDate,' '))=4)) and number(substring-after(substring-after($guessDate,' '),' '))=number(substring-after(substring-after($guessDate,' '),' ')) and string-length(substring-after(substring-after($guessDate,' '),' '))=4 and string-length(substring-before(substring-after($guessDate,' '),' '))=3">
      <xsl:if test="string-length(substring-before($guessDate,' '))=4">
       <xsl:call-template name="date:makeAbbrDateNumeric">
        <xsl:with-param name="abbrDate" select="concat(substring($guessDate,6,3),' ',substring($guessDate,1,2),' ',substring($guessDate,10))"/>
       </xsl:call-template>
      </xsl:if>
      <xsl:if test="string-length(substring-before($guessDate,' '))=3">
       <xsl:call-template name="date:makeAbbrDateNumeric">
        <xsl:with-param name="abbrDate" select="concat(substring($guessDate,5,3),' ',substring($guessDate,1,1),' ',substring($guessDate,9))"/>
       </xsl:call-template>
      </xsl:if>
     </xsl:when>
     <!-- DD Month CCYY -->
     <xsl:when test="number(substring-before($guessDate,' '))=number(substring-before($guessDate,' ')) and contains(substring-after($guessDate,' '),' ') and number(substring-after(substring-after($guessDate,' '),' '))=number(substring-after(substring-after($guessDate,' '),' ')) and string-length(substring-before(substring-after($guessDate,' '),' '))&gt;3">
      <xsl:call-template name="date:makeDateNumeric">
       <xsl:with-param name="friendlyDate" select="$guessDate"/>
       <xsl:with-param name="format-iso" select="'t'"/>
      </xsl:call-template>
     </xsl:when>
     <!-- DD Mon CCYY-->
     <xsl:when test="number(substring-before($guessDate,' '))=number(substring-before($guessDate,' ')) and contains(substring-after($guessDate,' '),' ') and number(substring-after(substring-after($guessDate,' '),' '))=number(substring-after(substring-after($guessDate,' '),' ')) and string-length(substring-before(substring-after($guessDate,' '),' '))=3">
      <xsl:call-template name="date:makeAbbrDateNumeric">
       <xsl:with-param name="abbrDate" select="concat(substring-before(substring-after($guessDate,' '),' '),' ',substring-before($guessDate,' '),' ',substring-after(substring-after($guessDate,' '),' '))"/>
      </xsl:call-template>
     </xsl:when>
     <xsl:otherwise>
      <xsl:value-of select="normalize-space($guessDate)"/>
     </xsl:otherwise>
    </xsl:choose>
   </xsl:when>
   <!-- YYYYMMDD -->
   <xsl:when test="string-length($guessDate)=8 and number($guessDate)=number($guessDate)">
    <xsl:value-of select="concat(format-number(number(substring($guessDate,1,4)),'0000'),'-',format-number(number(substring($guessDate,5,2)),'00'),'-',format-number(number(substring($guessDate,7,2)),'00'))"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="normalize-space($guessDate)"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template match="*" mode="format">
  <xsl:call-template name="get-lang">
   <xsl:with-param name="node" select="."/>
  </xsl:call-template>
  <xsl:variable name="alltxt">
   <xsl:apply-templates select="text()|*" mode="format-helper"/>
  </xsl:variable>
  <xsl:value-of select="normalize-space($alltxt)"/>
 </xsl:template>

 <xsl:template match="text()" mode="format-helper">
  <xsl:choose>
   <xsl:when test="starts-with(.,',') or starts-with(.,'.') or starts-with(.,':') or starts-with(.,';') or starts-with(.,'(') or starts-with(.,')')">
    <xsl:value-of select="normalize-space()"/>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of select="concat(' ',normalize-space())"/>
   </xsl:otherwise>
  </xsl:choose>
 </xsl:template>

 <xsl:template name="get-lang">
  <xsl:param name="node"/>
  <xsl:choose>
   <xsl:when test="$node/ancestor-or-self::*[@xml:lang][1] and $node/ancestor-or-self::*[@xml:lang][1]/@xml:lang!=$defaultLang">
    <xsl:attribute name="xml:lang">
     <xsl:value-of select="$node/ancestor-or-self::*[@xml:lang][1]/@xml:lang"/>
    </xsl:attribute>
   </xsl:when>
   <xsl:when test="$node/ancestor-or-self::*[@lang][1] and $node/ancestor-or-self::*[@lang][1]/@lang!=$defaultLang">
    <xsl:attribute name="xml:lang">
     <xsl:value-of select="$node/ancestor-or-self::*[@lang][1]/@lang"/>
    </xsl:attribute>
   </xsl:when>
<!-- If no ancestor in the document has an xml:lang attribute, then
     the root of the output is already given xml:lang=''
   <xsl:otherwise>
    <xsl:value-of select="''"/>
   </xsl:otherwise>-->
  </xsl:choose>
 </xsl:template>

 <xsl:template match="*" mode="format-helper">
  <xsl:apply-templates select="text()|*" mode="format-helper"/>
 </xsl:template>

 <xsl:template match="*[not(@class)]">
 </xsl:template>

</xsl:stylesheet>
