Project

Profile

Help

Bug #4389 » skeletonCommenter.xsl

Ken Holman, 2019-11-18 04:16

 
<?xml version="1.0" encoding="US-ASCII"?>
<?xml-stylesheet type="text/xsl" href="../xslstyle/xslstyle-docbook.xsl"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.CraneSoftwrights.com/ns/xslstyle"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:c="urn:X-Crane"
exclude-result-prefixes="xs xsd c"
version="2.0">

<xs:doc info="$Id$"
filename=".xsl" vocabulary="DocBook">
<xs:title>Create a commented skeleton of a BDNDR document model</xs:title>
<para>
For illustrative purposes to help the reader understand the markup
</para>
</xs:doc>

<!--========================================================================-->
<xs:doc>
<xs:title>Invocation parameters and input file</xs:title>
<para>
Input file is a BDNDR document model expressed in genericode.
</para>
</xs:doc>

<xs:output>
<para>The output is clear text</para>
</xs:output>
<xsl:output method="text"/>

<!--<xs:param ignore-ns='yes'>
<para>
</para>
</xs:param>
<xsl:param name="" select="''" as="xsd:string"/>-->

<!--========================================================================-->
<xs:doc>
<xs:title>Basic processing</xs:title>
</xs:doc>

<xs:function>
<para>
Access a row's column's value by its name
</para>
<xs:param name="c:row">
<para>The row of the model describing the BIE</para>
</xs:param>
<xs:param name="c:colName">
<para>The column value desired from that row</para>
</xs:param>
</xs:function>
<xsl:function name="c:col" as="xsd:string?">
<xsl:param name="c:row" as="element(Row)"/>
<xsl:param name="c:colName" as="xsd:string"/>
<xsl:sequence select="$c:row/Value[@ColumnRef=$c:colName]/SimpleValue"/>
</xsl:function>

<xs:key>
<para>Track items by their Dictionary Entry Name</para>
</xs:key>
<xsl:key name="c:bieByDEN" match="Row"
use="c:col(.,'DictionaryEntryName')"/>

<xs:key>
<para>Track ABIEs by their class name</para>
</xs:key>
<xsl:key name="c:bieByClass"
match="Row[not(c:col(.,'ComponentType')='ABIE')]
[not(c:col(.,'BPCML')=('','0'))]"
use="c:col(.,'ObjectClass')"/>

<xs:key>
<para>Track ABIEs by their class name</para>
</xs:key>
<xsl:key name="c:abieByClass"
match="Row[c:col(.,'ComponentType')='ABIE']"
use="c:col(.,'ObjectClass')"/>

<xs:key>
<para>Track ABIEs by their class name</para>
</xs:key>
<xsl:key name="c:abieByModel"
match="Row[c:col(.,'ComponentType')='ABIE']"
use="c:col(.,'ModelName')"/>

<xs:template>
<para>
The identity template is used to copy all nodes not already being handled
by other template rules.
</para>
</xs:template>
<xsl:template match="/">
<!--from the Document ABIE-->
<xsl:apply-templates select="/*/SimpleCodeList/Row
[count(key('c:abieByModel',c:col(.,'ModelName')))=1]"/>
</xsl:template>

<xs:template>
<para>
Process an ASBIE by working with its ABIE
</para>
<xs:param name="c:name">
<para>An overriding ASBIE name compared to the ABIE name</para>
</xs:param>
<xs:param name="c:definition">
<para>An overriding ASBIE definition compared to the ABIE definition</para>
</xs:param>
<xs:param name="c:cardinality">
<para>An ASBIE cardinality</para>
</xs:param>
<xs:param name="c:ancestors">
<para>A sequence of ancestor rows used to prevent infinite recursion</para>
</xs:param>
<xs:param name="c:indent">
<para>The running indentation based on ancestry</para>
</xs:param>
</xs:template>
<xsl:template match="Row[c:col(.,'ComponentType')='ABIE']">
<xsl:param name="c:name" as="xsd:string?"
select="c:col(.,'ComponentName')"/>
<xsl:param name="c:definition" as="xsd:string?"
select="c:col(.,'Definition')"/>
<xsl:param name="c:cardinality" as="xsd:string?" select="''"/>
<xsl:param name="c:ancestors" as="element(Row)*" tunnel="yes"/>
<xsl:param name="c:indent" as="xsd:string" select="''" tunnel="yes"/>
<xsl:variable name="c:prefix"
select="if( exists( $c:ancestors ) ) then 'cac:' else ''"/>
<xsl:variable name="c:namespaces"
select='if( exists( $c:ancestors )) then "" else
" xmlns:cac=""urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2""
xmlns:cbc=""urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2"""'/>
<xsl:choose>
<xsl:when test="some $c:a in $c:ancestors satisfies $c:a is .">
<!--avoid infinite loops-->
<xsl:value-of select="
'&lt;!--Recursive use of ',c:col(.,'ObjectClass)'),'-->&#xa;'"/>
</xsl:when>
<xsl:otherwise>
<!--start tag-->
<xsl:value-of select="
concat($c:indent,'&lt;',$c:prefix,$c:name,$c:namespaces,'>&#xa;')"/>
<!--documentation-->
<xsl:value-of select="concat(' ',$c:indent,'&lt;!--',$c:cardinality,
$c:definition,'-->&#xa;')"/>
<!--children-->
<xsl:apply-templates select="key('c:bieByClass',c:col(.,'ObjectClass'))">
<xsl:with-param name="c:ancestors" select="$c:ancestors,."
tunnel="yes"/>
<xsl:with-param name="c:indent" select="concat(' ',$c:indent)"
tunnel="yes"/>
</xsl:apply-templates>
<!--end tag-->
<xsl:value-of select="
concat($c:indent,'&lt;/',$c:prefix,$c:name,'>&#xa;')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>

<xs:template>
<para>
Process an ASBIE by working with its ABIE
</para>
</xs:template>
<xsl:template match="Row[c:col(.,'ComponentType')='ASBIE']">
<xsl:apply-templates
select="key('c:abieByClass',c:col(.,'AssociatedObjectClass'))">
<xsl:with-param name="c:name" select="c:col(.,'ComponentName')"/>
<xsl:with-param name="c:definition" select="c:col(.,'Definition')"/>
<xsl:with-param name="c:cardinality"
select="for $c:card in c:col(.,'Cardinality') return
concat(if( starts-with($c:card,'0') )
then 'optional' else 'mandatory',
if( ends-with($c:card,'n') )
then ', repeatable' else '',
' - ')"/>
</xsl:apply-templates>
</xsl:template>

<xs:template>
<para>
Process a BBIE by working with its ABIE
</para>
<xs:param name="c:ancestors">
<para>A sequence of ancestor rows used to prevent infinite recursion</para>
</xs:param>
<xs:param name="c:indent">
<para>The running indentation based on ancestry</para>
</xs:param>
</xs:template>
<xsl:template match="Row">
<xsl:param name="c:ancestors" as="element(Row)*" tunnel="yes"/>
<xsl:param name="c:indent" as="xsd:string" tunnel="yes"/>
<!--start tag-->
<xsl:value-of select="
concat($c:indent,'&lt;','cbc:',c:col(.,'ComponentName'),'>')"/>
<!--documentation-->
<xsl:value-of select="concat('&lt;!--',
for $c:card in c:col(.,'Cardinality') return
concat(if( starts-with($c:card,'0') )
then 'optional' else 'mandatory',
if( ends-with($c:card,'n') )
then ', repeatable' else '',
' - '),
c:col(.,'Definition'),'-->')"/>
<!--end tag-->
<xsl:value-of select="
concat('&lt;/','cbc:',c:col(.,'ComponentName'),'>&#xa;')"/>
</xsl:template>

</xsl:stylesheet>
(2-2/2)