Skip to content

Commit

Permalink
in LDF all core sections must belong to a part
Browse files Browse the repository at this point in the history
git-svn-id: https://slps.svn.sourceforge.net/svnroot/slps@674 ab42f6e0-554d-0410-b580-99e487e6eeb2
  • Loading branch information
grammarware committed Aug 3, 2009
1 parent 9e1861c commit f49d661
Show file tree
Hide file tree
Showing 10 changed files with 204 additions and 68 deletions.
6 changes: 5 additions & 1 deletion shared/python/xldf.py
Expand Up @@ -43,12 +43,16 @@ def normalise(tree):
for e in tree.findall('*'):
for e2 in e.findall('*'):
if len(e2.findall('content'))>1:
print '[????] In',identify(e),'/',identify(e2),'found double content!'
print '[++++] In',identify(e),'/',identify(e2),'found double content!'
first = e2.findall('content')[0]
for e3 in e2.findall('content')[1:]:
for e4 in e3.findall('*'):
first.append(e4)
e2.remove(e3)
for e in tree.findall('//content'):
if not len(e):
print '[++++] Empty content made explicit.'
ET.SubElement(e,'empty')
return

def main(xldffile,inldffile,outldffile):
Expand Down
17 changes: 12 additions & 5 deletions shared/python/xldfCommands.py
Expand Up @@ -171,7 +171,11 @@ def xldf_drop(localpath,cmd,tree):
if not found:
print '[----] xldf:drop failed: node',cmd.findtext('section'),'not found!'
return
tree.getroot().remove(found)
# houwtje-touwtje
try:
tree.getroot().remove(found)
except ValueError,e:
tree.findall('part')[0].remove(found)
print '[XLDF] drop('+cmd.findtext('section')+')'
return

Expand All @@ -196,14 +200,17 @@ def xldf_combine(localpath,cmd,tree):
continue
if found2.findall(s.tag):
# the same role present, appending
print '[////] Concatenating',s.tag,'of',cmd.findtext('section'),'and',cmd.findtext('with')
#print '[////] Concatenating',s.tag,'of',cmd.findtext('section'),'and',cmd.findtext('with')
content2content(s.findall('content')[0],found2.findall(s.tag+'/content')[0])
else:
# the same role absent, copying
print '[////] Copying',s.tag,'of',cmd.findtext('section'),'to',cmd.findtext('with')
#print '[////] Copying',s.tag,'of',cmd.findtext('section'),'to',cmd.findtext('with')
found2.append(s)
# wtf?
tree.getroot().remove(found)
try:
tree.getroot().remove(found)
except ValueError,e:
tree.findall('part')[0].remove(found)
print '[XLDF] combine('+cmd.findtext('section')+',',cmd.findtext('with')+')'
#else:
# print '[----] xldf:combine failed: don''t know how to place subsections in',found2.tag
Expand Down Expand Up @@ -258,7 +265,7 @@ def xldf_add_section(localpath,cmd,tree):
print '[XLDF] add-section to lexical part'
success = True
elif s.tag in ('core','annex'):
tree.getroot().append(s)
tree.findall('part')[0].append(s)
print '[XLDF] add-section to the',s.tag
success = True
elif s.tag == 'placeholder':
Expand Down
19 changes: 15 additions & 4 deletions shared/python/xsd2ldf.py
Expand Up @@ -107,16 +107,27 @@ def main(xsdfile,bgffile,ldffile):
el = ET.SubElement(section,'normativeReferences')
el = ET.SubElement(el,'content')
el = ET.SubElement(el,'list')
part = ET.SubElement(dtree,'part')
for p in stree.findall('/'+slpsns.xsd_('import')):
pel = ET.SubElement(el,'item')
pel.text = p.attrib['schemaLocation']
istree = ET.parse('/'.join(xsdfile.split('/')[:-1])+'/'+p.attrib['schemaLocation'])
mapXSD2LDF(istree,dtree,grammar)
mapXSD2LDF(istree,part,grammar)
print len(stree.findall('/'+slpsns.xsd_('import'))),'external schema(ta) imported.'

mapXSD2LDF(stree,dtree,grammar)

ET.ElementTree(dtree).write(ldffile)
if dtree.findall('part'):
part = dtree.findall('part')[0]
else:
part = ET.SubElement(dtree,'part')
mapXSD2LDF(stree,part,grammar)
# bit of normalisation
fullTree = ET.ElementTree(dtree)
for e in fullTree.findall('//content'):
if not len(e):
print '[++++] Empty content made explicit.'
ET.SubElement(e,'empty')
# serialise!
fullTree.write(ldffile)
return

def copymixedcontent (parent, name, stree, xpath):
Expand Down
35 changes: 34 additions & 1 deletion shared/xsl/ldf2tex.xslt
Expand Up @@ -119,7 +119,18 @@
<xsl:text>
%% START_CORE
</xsl:text>
<xsl:apply-templates select="core"/>
<xsl:choose>
<xsl:when test="count(part) = 1">
<xsl:apply-templates select="part/core"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="part">
<xsl:call-template name="treatPart">
<xsl:with-param name="part" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="backMatter/*">
<xsl:call-template name="sectionize">
<xsl:with-param name="target" select="."/>
Expand Down Expand Up @@ -282,6 +293,28 @@
</xsl:if>
</xsl:template>

<xsl:template name="treatPart">
<xsl:param name="part"/>
<xsl:text>\part{</xsl:text>
<!-- text -->
<xsl:if test="$part/title">
<xsl:value-of select="$part/title"/>
</xsl:if>
<xsl:text>}</xsl:text>
<!-- anchor -->
<xsl:text>\label{</xsl:text>
<xsl:choose>
<xsl:when test="$part/@id">
<xsl:value-of select="$part/@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name($part)"/>
</xsl:otherwise>
</xsl:choose>
<xsl:text>}</xsl:text>
<xsl:apply-templates select="$part/*"/>
</xsl:template>

<xsl:template name="subsectionize">
<xsl:param name="target"/>
<xsl:param name="level"/>
Expand Down
40 changes: 39 additions & 1 deletion shared/xsl/ldf2xhtml.xslt
Expand Up @@ -113,7 +113,19 @@
<xsl:with-param name="section" select="."/>
</xsl:call-template>
</xsl:for-each>
<xsl:apply-templates select="core"/>
<!--<xsl:apply-templates select="core"/>-->
<xsl:choose>
<xsl:when test="count(part) = 1">
<xsl:apply-templates select="part/core"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="part">
<xsl:call-template name="treatPart">
<xsl:with-param name="part" select="."/>
</xsl:call-template>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
<xsl:for-each select="backMatter/*">
<xsl:choose>
<xsl:when test="local-name() = 'placeholder'">
Expand Down Expand Up @@ -472,6 +484,32 @@
</xsl:if>-->
</xsl:template>

<xsl:template name="treatPart">
<xsl:param name="part"/>
<h1 xmlns="http://www.w3.org/1999/xhtml">
<!-- anchor -->
<a>
<xsl:attribute name="name">
<xsl:choose>
<xsl:when test="$part/@id">
<xsl:value-of select="$part/@id"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="local-name($part)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
</a>
<!-- text -->
<xsl:text>Part I. </xsl:text>
<!-- need to work on numbering -->
<xsl:if test="$part/title">
<xsl:value-of select="$part/title"/>
</xsl:if>
</h1>
<xsl:apply-templates select="$part/*"/>
</xsl:template>

<xsl:template match="core|annex">
<xsl:call-template name="sectionize">
<xsl:with-param name="target" select="."/>
Expand Down
2 changes: 1 addition & 1 deletion topics/languedoc/ldf/prepare.xbgf
Expand Up @@ -4,7 +4,7 @@
xmlns:xbgf="http://planet-sl.org/xbgf">

<xbgf:vertical>
<nonterminal>frontSection</nonterminal>
<nonterminal>topSection</nonterminal>
</xbgf:vertical>
<xbgf:vertical>
<nonterminal>frontList</nonterminal>
Expand Down
132 changes: 82 additions & 50 deletions topics/languedoc/ldf/xldf/beautify.xldf
Expand Up @@ -25,32 +25,16 @@
</marked>
</bgf:expression>
<bgf:expression>
<star>
<bgf:expression>
<selectable>
<selector>placeholder</selector>
<bgf:expression>
<nonterminal>generated</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</star>
</bgf:expression>
<bgf:expression>
<marked>
<selectable>
<selector>frontMatter</selector>
<bgf:expression>
<selectable>
<selector>frontMatter</selector>
<star>
<bgf:expression>
<plus>
<bgf:expression>
<nonterminal>frontSection</nonterminal>
</bgf:expression>
</plus>
<nonterminal>topSection</nonterminal>
</bgf:expression>
</selectable>
</star>
</bgf:expression>
</marked>
</selectable>
</bgf:expression>
<bgf:expression>
<optional>
Expand Down Expand Up @@ -93,16 +77,61 @@
</optional>
</bgf:expression>
<bgf:expression>
<plus>
<choice>
<bgf:expression>
<plus>
<bgf:expression>
<selectable>
<selector>core</selector>
<bgf:expression>
<nonterminal>structuredSection</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</plus>
</bgf:expression>
<bgf:expression>
<plus>
<bgf:expression>
<marked>
<bgf:expression>
<selectable>
<selector>part</selector>
<bgf:expression>
<plus>
<bgf:expression>
<selectable>
<selector>core</selector>
<bgf:expression>
<nonterminal>structuredSection</nonterminal>
</bgf:expression>
</selectable>
</bgf:expression>
</plus>
</bgf:expression>
</selectable>
</bgf:expression>
</marked>
</bgf:expression>
</plus>
</bgf:expression>
</choice>
</bgf:expression>
<bgf:expression>
<optional>
<bgf:expression>
<selectable>
<selector>core</selector>
<selector>backMatter</selector>
<bgf:expression>
<nonterminal>structuredSection</nonterminal>
<star>
<bgf:expression>
<nonterminal>topSection</nonterminal>
</bgf:expression>
</star>
</bgf:expression>
</selectable>
</bgf:expression>
</plus>
</optional>
</bgf:expression>
<bgf:expression>
<star>
Expand All @@ -122,36 +151,38 @@
</xbgf:anonymize>
<xbgf:extract>
<bgf:production>
<nonterminal>frontMatter</nonterminal>
<nonterminal>anyTopSections</nonterminal>
<bgf:expression>
<plus>
<star>
<bgf:expression>
<nonterminal>frontSection</nonterminal>
<nonterminal>topSection</nonterminal>
</bgf:expression>
</plus>
</star>
</bgf:expression>
</bgf:production>
</xbgf:extract>
<xbgf:extract>
<bgf:production>
<nonterminal>lists</nonterminal><bgf:expression>
<plus>
<bgf:expression>
<nonterminal>frontList</nonterminal>
</bgf:expression>
</plus>
</bgf:expression>
<nonterminal>lists</nonterminal>
<bgf:expression>
<plus>
<bgf:expression>
<nonterminal>frontList</nonterminal>
</bgf:expression>
</plus>
</bgf:expression>
</bgf:production>
</xbgf:extract>
<xbgf:extract>
<bgf:production>
<nonterminal>lexicalPart</nonterminal><bgf:expression>
<plus>
<bgf:expression>
<nonterminal>lexicalSection</nonterminal>
</bgf:expression>
</plus>
</bgf:expression>
<nonterminal>lexicalPart</nonterminal>
<bgf:expression>
<plus>
<bgf:expression>
<nonterminal>lexicalSection</nonterminal>
</bgf:expression>
</plus>
</bgf:expression>
</bgf:production>
</xbgf:extract>
</xldf:transform-grammar>
Expand Down Expand Up @@ -266,9 +297,10 @@
<sequence>
<bgf:expression>
<selectable>
<selector>name</selector><bgf:expression>
<value>string</value>
</bgf:expression>
<selector>name</selector>
<bgf:expression>
<value>string</value>
</bgf:expression>
</selectable>
</bgf:expression>
<bgf:expression>
Expand Down Expand Up @@ -345,9 +377,9 @@
</bgf:production>
</xbgf:anonymize>
</xldf:transform-grammar>
<!--


<!--
<xldf:transform-grammar>
<target>simpleType-body</target>
<xbgf:vertical>
Expand Down

0 comments on commit f49d661

Please sign in to comment.