Skip to content

Commit

Permalink
formex transform now at POC stage
Browse files Browse the repository at this point in the history
  • Loading branch information
staffanm committed Jun 11, 2018
1 parent 2d45762 commit d0dac2a
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
17 changes: 14 additions & 3 deletions ferenda/sources/legal/eu/eurlex.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ def render_xhtml_tree(self, doc):
return doc.body

def metadata_from_basefile(self, doc):
from pudb import set_trace; set_trace()
desc = Describer(doc.meta, doc.uri)
desc.rel(CDM.resource_legal_id_celex, Literal(doc.basefile))
# the sixth letter in
Expand Down Expand Up @@ -377,19 +376,31 @@ def parse(self, doc):
def parse_formex(self, doc, source):
parser = etree.XMLParser(remove_blank_text=True)
sourcetree = etree.parse(source, parser).getroot()
from pudb import set_trace; set_trace()
fp = self.resourceloader.openfp("xsl/formex.xsl")
xslttree = etree.parse(fp, parser)
transformer = etree.XSLT(xslttree)
params = etree.XSLT
from pudb import set_trace; set_trace()
resulttree = transformer(sourcetree,
about=XSLT.strparam(doc.uri),
rdftype=XSLT.strparam(str(doc.meta.value(URIRef(doc.uri), RDF.type))))
return resulttree
# re-parse to fix whitespace
buffer = BytesIO(etree.tostring(resulttree, encoding="utf-8"))
return etree.parse(buffer, parser)

def render_xhtml_validate(self, xhtmldoc):
def checknode(node):
if node.tag.split("}")[-1].isupper():
raise errors.InvalidTree("Node %s has not been properly transformed from Formex to XHTML" % node.tag)
for child in node:
if type(child).__name__ == "_Element":
checknode(child)
try:
checknode(xhtmldoc.getroot())
except errors.InvalidTree as e:
return str(e)
return super(EURLex, self).render_xhtml_validate(xhtmldoc)


def tabs(self):
return []
Expand Down
27 changes: 25 additions & 2 deletions ferenda/sources/legal/eu/res/xsl/formex.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Note: this template expects Formex version 4 (http://formex.publications.europa.
<xsl:param name="about"/>
<xsl:param name="rdftype"/>
<xsl:output indent="yes"/>

<xsl:template match="/">
<html xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.w3.org/1999/xhtml http://www.w3.org/MarkUp/SCHEMA/xhtml-rdfa-2.xsd"
Expand Down Expand Up @@ -94,6 +95,8 @@ Note: this template expects Formex version 4 (http://formex.publications.europa.
<span class="oj-ref"><xsl:apply-templates/></span>
</xsl:template>

<xsl:template match="QUOT.START|QUOT.END"><xsl:value-of disable-output-escaping="yes" select="concat('&amp;#x',@CODE,';')"/></xsl:template>


<xsl:template match="CONSID">
<!-- eg: sv: "skäl" -->
Expand All @@ -111,7 +114,13 @@ Note: this template expects Formex version 4 (http://formex.publications.europa.
</xsl:template>

<xsl:template match="DIVISION">
<div typeof="bibo:DocumentPart" about="$about#..." property="dcterms:title" content="{TITLE/TI/P/HT} // {TITLE/STI/P/HT}">
<div typeof="bibo:DocumentPart" about="{$about}#D{count(preceding-sibling::DIVISION)+1}" property="dcterms:title" content="{TITLE/TI/P/HT} // {TITLE/STI/P/HT}">
<xsl:apply-templates/>
</div>
</xsl:template>

<xsl:template match="DIVISION/DIVISION">
<div typeof="bibo:DocumentPart" about="{$about}#D{count(../preceding-sibling::DIVISION)+1}-{count(preceding-sibling::DIVISION)+1}" property="dcterms:title" content="{TITLE/TI/P/HT} // {TITLE/STI/P/HT}">
<xsl:apply-templates/>
</div>
</xsl:template>
Expand Down Expand Up @@ -154,11 +163,25 @@ Note: this template expects Formex version 4 (http://formex.publications.europa.
</ol>
</xsl:template>

<xsl:template match="LIST[@TYPE='ARAB']">
<ol type='1'>
<xsl:apply-templates/>
</ol>
</xsl:template>

<xsl:template match="LIST[@TYPE='DASH']">
<ul class="dash">
<xsl:apply-templates/>
</ul>
</xsl:template>

<xsl:template match="ITEM">
<!-- fixme: find better rdf predicate -->
<li property="rinfoex:punkt" content="{NP/NO.P}"><xsl:apply-templates select="NP/TXT"/></li>
</xsl:template>


<xsl:template match="FT"><span class="ft"><xsl:apply-templates/></span></xsl:template>

<xsl:template match="FINAL">
<div class="final">
<xsl:apply-templates/>
Expand Down

0 comments on commit d0dac2a

Please sign in to comment.