Skip to content

Commit

Permalink
full support for parsing the specs now
Browse files Browse the repository at this point in the history
  • Loading branch information
kepper committed Dec 4, 2018
1 parent 4dde4af commit 91fa9b9
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 13 deletions.
40 changes: 35 additions & 5 deletions tools/xsl/elementHandling.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -144,24 +144,43 @@
</xsl:for-each>
</xsl:variable>
<xsl:variable name="childs" select="$direct.childs | $class.childs | $macro.childs" as="node()*"/>
<xsl:variable name="allows.anyXML" select="exists($object/tei:content/rng:element[rng:anyName and rng:zeroOrMore/rng:attribute/rng:anyName and rng:zeroOrMore//rng:text and rng:zeroOrMore//rng:ref[@name = $object/@ident]])" as="xs:boolean"/>
<xsl:variable name="allows.text" select="xs:boolean(not($allows.anyXML) and exists($object/tei:content//rng:text))" as="xs:boolean"/>

<xsl:choose>
<xsl:when test="count($childs) gt 0">
<xsl:when test="count($childs) gt 0 or $allows.text">
<xsl:variable name="childs.compact" as="node()*">
<xsl:if test="$allows.text">
<span class="ident textualContent" title="textual content">textual content</span>
</xsl:if>
<xsl:for-each select="$childs/self::tei:elementSpec">
<xsl:sort select="@ident" data-type="text"/>
<xsl:variable name="current.elem" select="@ident" as="xs:string"/>
<xsl:variable name="desc" select="normalize-space(string-join(tei:desc//text(),' '))" as="xs:string"/>
<xsl:if test="position() gt 1">
<xsl:if test="position() gt 1 or $allows.text">
<xsl:value-of select="', '"/>
</xsl:if>
<span class="ident element" title="{$desc}">
<a class="link_odd_elementSpec" href="{tools:linkToElement($current.elem)}"><xsl:value-of select="$current.elem"/></a>
</span>
</xsl:for-each>
</xsl:variable>
<xsl:variable name="childs.by.class" select="tools:getChildsByModel($object)" as="node()*"/>
<xsl:variable name="childs.by.class" as="node()*">
<xsl:if test="$allows.text">
<div class="textualContent" title="textual content">
textual content
</div>
</xsl:if>
<xsl:sequence select="tools:getChildsByModel($object)"/>
</xsl:variable>
<xsl:variable name="childs.by.module" as="node()*">

<xsl:if test="$allows.text">
<div class="textualContent" title="textual content">
textual content
</div>
</xsl:if>

<xsl:for-each select="distinct-values($childs/self::tei:elementSpec/@module)">
<xsl:sort select="." data-type="text"/>
<xsl:variable name="current.module" select="." as="xs:string"/>
Expand All @@ -170,11 +189,12 @@
<xsl:variable name="ident" select="$current.module" as="xs:string"/>
<xsl:variable name="desc" select="normalize-space(string-join($mei.source//tei:moduleSpec[@ident = $current.module]/tei:desc/text(),' '))" as="xs:string"/>
<xsl:variable name="content" as="node()*">

<xsl:for-each select="$relevant.element.names">
<xsl:sort select="." data-type="text"/>
<xsl:variable name="current.elem" select="." as="xs:string"/>

<div class="elementRef">
<div class="elementRef" title="{$current.elem}">
<a class="link_odd_elementSpec" href="{tools:linkToElement($current.elem)}"><xsl:value-of select="$current.elem"/></a>
<span class="elementDesc">
<xsl:apply-templates select="$elements/self::tei:elementSpec[@ident = $current.elem]/tei:desc" mode="parse.odd"/>
Expand All @@ -196,11 +216,21 @@

<xsl:sequence select="tools:getTabbedFacet('mayContain','May Contain',$contents)"/>
</xsl:when>
<xsl:when test="$allows.anyXML">
<div class="facet mayContain" id="mayContain">
<div class="label">May Contain</div>
<div class="statement text">
any XML element, with any attribute <span class="emptyStatement">(<em><xsl:value-of select="$object/@ident"/> is self-nested</em>)</span>
</div>
</div>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="prefix" select="if(local-name($object) = 'elementSpec') then('&lt;') else('')" as="xs:string"/>
<xsl:variable name="postfix" select="if(local-name($object) = 'elementSpec') then('&gt;') else('')" as="xs:string"/>
<div class="facet mayContain" id="mayContain">
<div class="label">May Contain</div>
<div class="statement text">
– <span class="emptyStatement">(<em>&lt;<xsl:value-of select="$object/@ident"/>/&gt; may not have child elements</em>)</span>
– <span class="emptyStatement">(<em><xsl:value-of select="$prefix || $object/@ident || $postfix"/> may not have child elements</em>)</span>
</div>
</div>
</xsl:otherwise>
Expand Down
2 changes: 1 addition & 1 deletion tools/xsl/globalFunctions.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@
</xsl:template>
<xsl:function name="tools:linkToMacroGroup" as="xs:string">
<xsl:param name="datatype" as="xs:string"/>
<xsl:value-of select="$version || '/data-types/' || lower-case($datatype) || '.html'"/>
<xsl:value-of select="$version || '/macro-groups/' || lower-case($datatype) || '.html'"/>
</xsl:function>


Expand Down
44 changes: 44 additions & 0 deletions tools/xsl/macrogroupHandling.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,48 @@
</xd:desc>
</xd:doc>

<xd:doc scope="component">
<xd:desc>This template resolves Macro Groups (Parameter entities)</xd:desc>
</xd:doc>
<xsl:template match="tei:macroSpec[@type = 'pe']" mode="parse.odd">
<xsl:variable name="macro.group" select="." as="node()"/>
<div class="macrogroupSpec">
<h3 id="{$macro.group/@ident}"><xsl:value-of select="$macro.group/@ident"/></h3>
<div class="specs">
<div class="desc">
<xsl:apply-templates select="$macro.group/tei:desc/node()" mode="#current"/>
<xsl:variable name="refs" select="$guidelines.references/descendant-or-self::*:ref[@ident = $macro.group/@ident]" as="node()*"/>
<xsl:if test="count($refs) gt 0">
<div class="chapterLinksBox">
<xsl:for-each select="$refs">
<xsl:sort select="@sortnum" data-type="text"/>
<a class="chapterLink{if(@desc='true') then(' desc') else()}" href="{@link}"><xsl:value-of select="@chapter"/></a><xsl:if test="position() lt count($refs)">,</xsl:if>
</xsl:for-each>
</div>
</xsl:if>
</div>

<xsl:sequence select="tools:getModuleFacet($macro.group/@module)"/>

<xsl:sequence select="tools:getContainingParentsFacet($macro.group)"/>

<xsl:sequence select="tools:getContainedChildsFacet($macro.group)"/>

<xsl:sequence select="tools:getRemarksFacet($macro.group)"/>

<xsl:sequence select="tools:getSchematronFacet($macro.group)"/>

<xsl:sequence select="tools:getDeclarationFacet($macro.group)"/>

</div>
<xsl:sequence select="tools:getJavascriptForTabs()"/>
</div>
</xsl:template>

<!--<xsl:function name="tools:getMacroGroupParentsFacet" as="node()">
<xsl:param name="macro.group" as="node()"/>
</xsl:function>-->

</xsl:stylesheet>
34 changes: 29 additions & 5 deletions tools/xsl/modelClassHandling.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -152,21 +152,37 @@
<xsl:param name="object" as="node()"/>

<xsl:variable name="is.element" select="local-name($object) = 'elementSpec'" as="xs:boolean"/>
<xsl:variable name="is.model" select="local-name($object) = 'classSpec' and $object/@type = 'model'" as="xs:boolean"/>
<xsl:variable name="is.macro" select="local-name($object) = 'macroSpec' and $object/@type = 'pe'" as="xs:boolean"/>
<xsl:variable name="ident" select="if($is.element) then('direct children') else($object/@ident)" as="xs:string"/>
<xsl:variable name="desc" select="if($is.element) then('') else('(' || $object/@module || ') ' || normalize-space(string-join($object/tei:desc/text(),' ')))" as="xs:string"/>

<xsl:variable name="allows.text" select="exists($object//tei:content//rng:text)" as="xs:boolean"/>

<xsl:if test="$allows.text">
<xsl:message select="$object/@ident || ' allows text'"></xsl:message>
</xsl:if>

<xsl:variable name="relevant.elements" as="node()*">
<xsl:choose>
<xsl:when test="$is.element">
<xsl:sequence select="$elements/self::tei:elementSpec[@ident = $object//tei:content//rng:ref[not(starts-with(@name,'model.'))]/@name]"/>
<xsl:sequence select="$elements/self::tei:elementSpec[@ident = $object//tei:content//rng:ref[not(starts-with(@name,'model.')) and not(starts-with(@name, 'macro.'))]/@name]"/>
</xsl:when>
<xsl:otherwise>
<xsl:when test="$is.model">
<xsl:sequence select="$elements/self::tei:elementSpec[.//tei:memberOf[@key = $object/@ident]]"/>
</xsl:otherwise>
</xsl:when>
<xsl:when test="$is.macro">
<xsl:sequence select="$elements/self::tei:elementSpec[@ident = $object//tei:content//rng:ref[not(starts-with(@name,'model.'))]/@name]"/>
</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:if test="not($is.element) or count($relevant.elements) gt 0">
<xsl:variable name="content" as="node()*">
<xsl:if test="$allows.text">
<div class="textualContent" title="textual content">
textual content
</div>
</xsl:if>
<xsl:for-each select="$relevant.elements">
<xsl:sort select="@ident" data-type="text"/>
<xsl:variable name="current.elem" select="@ident" as="xs:string"/>
Expand All @@ -181,7 +197,12 @@
</div>
</xsl:for-each>
<xsl:if test="not($is.element)">
<xsl:variable name="inheriting.models" select="$model.classes/self::tei:classSpec[.//tei:memberOf/@key = $object/@ident]" as="node()*"/>
<xsl:variable name="inheriting.models" as="node()*">
<xsl:sequence select="$model.classes/self::tei:classSpec[.//tei:memberOf/@key = $object/@ident]"/>
<xsl:sequence select="$macro.groups/self::tei:macroSpec[.//tei:memberOf/@key = $object/@ident]"/>
<xsl:sequence select="$model.classes/self::tei:classSpec[@ident = $object/tei:content//rng:ref/@name]"/>
<xsl:sequence select="$macro.groups/self::tei:macroSpec[@ident = $object/tei:content//rng:ref/@name and not(@ident = $object/@ident)]"/>
</xsl:variable>
<xsl:for-each select="$inheriting.models">
<xsl:sequence select="tools:getChildsByModel(.)"/>
</xsl:for-each>
Expand All @@ -191,7 +212,10 @@
</xsl:if>

<xsl:if test="$is.element">
<xsl:variable name="inheriting.models" select="$model.classes/self::tei:classSpec[@ident = $object//tei:content//rng:ref[starts-with(@name,'model.')]/@name]" as="node()*"/>
<xsl:variable name="inheriting.models" as="node()*">
<xsl:sequence select="$model.classes/self::tei:classSpec[@ident = $object//tei:content//rng:ref[starts-with(@name,'model.')]/@name]"/>
<xsl:sequence select="$macro.groups/self::tei:macroSpec[@ident = $object/tei:content//rng:ref/@name]"/>
</xsl:variable>
<xsl:for-each select="$inheriting.models">
<xsl:sequence select="tools:getChildsByModel(.)"/>
</xsl:for-each>
Expand Down
5 changes: 3 additions & 2 deletions tools/xsl/parseOdd.xsl
Original file line number Diff line number Diff line change
Expand Up @@ -133,9 +133,10 @@
<!-- remove attributes for macroSpec's ODD -->
<xsl:template match="tei:macroSpec//@ns | tei:macroSpec//@predeclare | tei:macroSpec//@status | tei:macroSpec//@autoPrefix" mode="preserveSpace" priority="2">
<xsl:param name="getODD" tunnel="yes" as="xs:boolean?"/>
<!--<xsl:if test="not($getODD) or $getODD = false()">
<!-- keep it if it's macro.anyXML -->
<xsl:if test="parent::rng:nsName and ancestor::rng:element">
<xsl:next-match/>
</xsl:if>-->
</xsl:if>
</xsl:template>

<!-- the following templates are used to support the unicode "reverse solidus overlay" character (u20E5) -->
Expand Down

0 comments on commit 91fa9b9

Please sign in to comment.