Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
eoa-publication-model/stylesheets/rng_to_odd/rng_to_analysis/rnc_analyse_structure.xsl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
440 lines (415 sloc)
15.3 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<stylesheet version="2.0" | |
xmlns="http://www.w3.org/1999/XSL/Transform" | |
xmlns:tei="http://www.tei-c.org/ns/1.0" | |
xmlns:rng="http://relaxng.org/ns/structure/1.0" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xmlns:eoa="http://www.edition-open-access.de/ns" | |
xmlns:f="http://fxsl.sf.net/" | |
exclude-result-prefixes="tei f xs" | |
> | |
<import href="xpath_unique_expr_simple.xsl"/> | |
<import href="xpath_unique_expr_advanced.xsl"/> | |
<template name="structure"> | |
<element name="grammar" namespace="{$rng_namespace}"> | |
<element name="start" namespace="{$rng_namespace}"> | |
<copy-of select="//rng:start/*"/> | |
</element> | |
<for-each-group | |
select="//rng:define" | |
group-by="rng:element/rng:name/text()" | |
> | |
<variable name="elem_name" select="current-grouping-key()"/> | |
<variable name="definitions" select="current-group()"/> | |
<element name="element" namespace="{$eoa_namespace}"> | |
<attribute name="name"> | |
<value-of select="$elem_name"/> | |
</attribute> | |
<element name="definitions" namespace="{$eoa_namespace}"> | |
<for-each select="current-group()"> | |
<variable name="current_definition" as="element()" select="."/> | |
<variable name="xpath_unique_expr_simple" as="xs:string?"> | |
<apply-templates mode="xpath_unique_expr_simple" select="."> | |
<with-param name="definitions" select="$definitions"/> | |
</apply-templates> | |
</variable> | |
<element name="define" namespace="{$eoa_namespace}"> | |
<attribute name="name"><value-of select="@name"/></attribute> | |
<if test="$xpath_unique_expr_simple"> | |
<element name="unique_xpath_expr_simple" namespace="{$eoa_namespace}"> | |
<value-of select="$xpath_unique_expr_simple"/> | |
</element> | |
</if> | |
<element name="parents" namespace="{$eoa_namespace}"> | |
<for-each select="//rng:define[rng:element//rng:ref/@name = $current_definition/@name]"> | |
<element name="parent" namespace="{$eoa_namespace}"> | |
<value-of select="@name"/> | |
</element> | |
</for-each> | |
</element> | |
<!-- copy rng:define element --> | |
<copy-of select="."/> | |
</element> | |
</for-each> | |
</element> | |
</element> | |
</for-each-group> | |
</element> | |
</template> | |
<template mode="structure_advanced" match="eoa:element"> | |
<value-of select="eoa:info('structure_advanced', concat('calculating element ', @name))"/> | |
<copy> | |
<apply-templates mode="structure_advanced" select="@* | *[not( self::eoa:definitions )]"/> | |
<element name="definitions" namespace="{$eoa_namespace}"> | |
<value-of select="eoa:debug('structure_advanced', concat('calculating unique xpath expressions for all definitions of element ', @name,':'))"/> | |
<variable name="xpath_unique_expr_advanced"> | |
<call-template name="xpath_unique_expr_advanced"> | |
<with-param name="define_ids" as="xs:string*" select=".//rng:define/@name"/> | |
</call-template> | |
</variable> | |
<!-- | |
<message> | |
<text>map:</text> | |
<value-of select="$newline"/> | |
<for-each select="$xpath_unique_expr_advanced/eoa:result"> | |
<call-template name="print_map"> | |
<with-param name="print_value" select="f:print_path()"/> | |
</call-template> | |
</for-each> | |
</message> | |
--> | |
<variable name="problems" as="element(eoa:problems)?" select="$xpath_unique_expr_advanced/eoa:problems"/> | |
<if test="$problems"> | |
<value-of select="eoa:warning('structure_advanced', 'there are problems with this element:')"/> | |
<for-each select="$problems/eoa:problem"> | |
<value-of select="eoa:warning('structure_advanced', concat(eoa:object, ': ', eoa:message))"/> | |
</for-each> | |
</if> | |
<for-each select="eoa:definitions/eoa:define"> | |
<value-of select="eoa:info('structure_advanced', concat('calculating definition ', @name))"/> | |
<!-- convert "eoa:values -> eoa:path": --> | |
<variable name="unique_xpath_expressions_values" as="element()*"> | |
<for-each select="$xpath_unique_expr_advanced/eoa:result/eoa:entry[eoa:key = current()/rng:define/@name]/eoa:value"> | |
<element name="path" namespace="{$eoa_namespace}"> | |
<sequence select="*"/> | |
</element> | |
</for-each> | |
</variable> | |
<variable name="unique_xpath_expressions_resolved" as="element(eoa:path)*"> | |
<apply-templates mode="resolve_paths" select="$unique_xpath_expressions_values"> | |
<with-param name="definitions_root" select="/"/> | |
</apply-templates> | |
</variable> | |
<!-- | |
<variable name="loops_str" as="xs:string*"> | |
<for-each select="$unique_xpath_expressions/eoa:loop"> | |
<value-of select="f:apply(f:print_path(), .)"/> | |
</for-each> | |
</variable> | |
--> | |
<apply-templates mode="structure_advanced" select="."> | |
<with-param name="unique_xpath_expr" select="$unique_xpath_expressions_resolved"/> | |
<with-param name="problems" select="$problems/eoa:problem[eoa:object = current()/@name]"/> | |
</apply-templates> | |
</for-each> | |
</element> | |
</copy> | |
</template> | |
<template mode="structure_advanced" match="eoa:define"> | |
<param name="unique_xpath_expr" as="element(eoa:path)*" select="()"/> | |
<param name="problems" as="element(eoa:problem)*" select="()"/> | |
<variable name="is_rng_supported" as="xs:string?"> | |
<apply-templates mode="is_rng_supported" select="rng:define"/> | |
</variable> | |
<if test="$is_rng_supported"> | |
<value-of select="eoa:warning( 'structure_advanced', concat('problem in the rng for element ', rng:define/@name, '. reason: ', $is_rng_supported) )"/> | |
</if> | |
<value-of select="eoa:debug( 'structure_advanced', 'calculating rng_no_attributes:')"/> | |
<variable name="no_attributes" as="element(rng:define)"> | |
<apply-templates mode="no_attributes" select="rng:define"/> | |
</variable> | |
<value-of select="eoa:debug( 'structure_advanced', 'calculating rng_only_attributes:')"/> | |
<variable name="only_attributes" as="element(rng:define)"> | |
<apply-templates mode="only_attributes" select="rng:define"/> | |
</variable> | |
<copy> | |
<copy-of select="@*"/> | |
<choose> | |
<!-- problems: --> | |
<when test="not($problems) and not($is_rng_supported)"> | |
<!-- unique_xpath_expr: --> | |
<element name="unique_xpath_expr" namespace="{$eoa_namespace}"> | |
<for-each select="$unique_xpath_expr"> | |
<element name="entry" namespace="{$eoa_namespace}"> | |
<copy-of select="."/> | |
</element> | |
</for-each> | |
</element> | |
</when> | |
<otherwise> | |
<element name="problems" namespace="{$eoa_namespace}"> | |
<sequence select="$problems"/> | |
<if test="$is_rng_supported"> | |
<element name="elemenets_and_attrs_mixed" namespace="{$eoa_namespace}"> | |
<value-of select="$is_rng_supported"/> | |
</element> | |
</if> | |
</element> | |
</otherwise> | |
</choose> | |
<!-- inherited content: --> | |
<copy-of select="*[not(self::rng:define)]"/> | |
<!-- rng:define: --> | |
<element name="rng" namespace="{$eoa_namespace}"> | |
<copy-of select="rng:define"/> | |
</element> | |
<element name="rng_no_attributes" namespace="{$eoa_namespace}"> | |
<copy-of select="$no_attributes"/> | |
</element> | |
<element name="rng_only_attributes" namespace="{$eoa_namespace}"> | |
<copy-of select="$only_attributes"/> | |
</element> | |
<variable name="only_attributes_dnf_prepare"> | |
<apply-templates mode="rng_dnf_prepare" select="$only_attributes"/> | |
</variable> | |
<element name="rng_only_attributes_prepare" namespace="{$eoa_namespace}"> | |
<copy-of select="$only_attributes_dnf_prepare"/> | |
</element> | |
<variable name="only_attributes_dnf_intermediate"> | |
<apply-templates mode="rng_to_dnf" select="$only_attributes_dnf_prepare"/> | |
</variable> | |
<element name="rng_only_attributes_dnf_intermediate" namespace="{$eoa_namespace}"> | |
<copy-of select="$only_attributes_dnf_intermediate"/> | |
</element> | |
<element name="rng_only_attributes_dnf" namespace="{$eoa_namespace}"> | |
<apply-templates mode="rng_dnf_finish" select="$only_attributes_dnf_intermediate"/> | |
</element> | |
</copy> | |
</template> | |
<!-- default template: copy everything --> | |
<template mode="structure_advanced" match="@* | node()"> | |
<copy> | |
<apply-templates mode="structure_advanced" select="@*|node()"/> | |
</copy> | |
</template> | |
<!-- return error string, if attributes and references cannot be seperated --> | |
<template mode="is_rng_supported" as="xs:string?" | |
match="element()" | |
> | |
<choose> | |
<!-- if an element has several kids --> | |
<when test="count(*[not(self::rng:name)]) > 1"> | |
<variable name="problems" as="xs:string?"> | |
<value-of> | |
<!-- if kids that contain "rng:attribute" also contain "rng:ref" --> | |
<for-each select="*[not(self::rng:name)][descendant-or-self::rng:attribute][rng:ref]"> | |
<!-- ERROR! --> | |
<value-of select="name()"/> | |
<text> contains rng:attribute and rng:ref elements!</text> | |
<if test="position() = last()"> | |
<value-of select="$newline"/> | |
</if> | |
</for-each> | |
</value-of> | |
</variable> | |
<choose> | |
<when test="$problems"> | |
<value-of select="$problems"/> | |
</when> | |
<otherwise> | |
<value-of select="()"/> | |
</otherwise> | |
</choose> | |
</when> | |
<otherwise> | |
<apply-templates mode="is_rng_supported" select="element()"/> | |
</otherwise> | |
</choose> | |
</template> | |
<!-- filter out anything concerning attributes: --> | |
<template mode="no_attributes" match="rng:attribute"> | |
<value-of select="eoa:error( 'structure_advanced', 'no_attributes called with rng:attribute')"/> | |
<!-- | |
<element name="empty" namespace="{$rng_namespace}"/> | |
--> | |
</template> | |
<!-- clean a definition from anything concerning attributes: --> | |
<template mode="no_attributes" as="element()?" | |
match="*" | |
> | |
<variable name="new_children"> | |
<choose> | |
<!-- if an element has multiple kids --> | |
<when test="count(*[not(self::rng:name)]) > 1"> | |
<!-- | |
<message><value-of select="eoa:debug( concat('no_attributes with ', name(), '. multiple kids: ', string-join(*[not(descendant-or-self::rng:attribute)]/name(),', ')))"/></message> | |
--> | |
<copy> | |
<apply-templates mode="no_attributes" select="@*"/> | |
<apply-templates mode="no_attributes" select="*[not(descendant-or-self::rng:attribute)] | text()"/> | |
</copy> | |
</when> | |
<otherwise> | |
<!-- | |
<message><value-of select="eoa:debug( concat('no_attributes with ', name(), '. single kid: ', string-join(*[not(self::rng:attribute)]/name(), ', ')))"/></message> | |
--> | |
<copy> | |
<apply-templates mode="no_attributes" select="@*"/> | |
<apply-templates mode="no_attributes" select="*[not(self::rng:attribute)] | text()"/> | |
</copy> | |
</otherwise> | |
</choose> | |
</variable> | |
<choose> | |
<when test="self::rng:element and count($new_children/*/*[not(self::rng:name)]) = 0"> | |
<copy> | |
<rng:empty/> | |
</copy> | |
</when> | |
<when test="(self::rng:group or self::rng:choice) and (count($new_children/*/*) = 0 or count($new_children/*/*[not(self::rng:empty)]) = 0)"> | |
<rng:empty/> | |
</when> | |
<otherwise> | |
<copy-of select="$new_children/*"/> | |
</otherwise> | |
</choose> | |
</template> | |
<template mode="no_attributes" match="@*"> | |
<copy/> | |
<!-- | |
<copy> | |
<apply-templates mode="no_attributes" select="node() | @*"/> | |
</copy> | |
--> | |
</template> | |
<!-- clean a definition keeping only the parts concerning attributes: --> | |
<template mode="only_attributes" match="rng:ref"> | |
<value-of select="eoa:error( 'structure_advanced', 'only_attributes called with rng:ref')"/> | |
</template> | |
<template mode="only_attributes" | |
match="rng:attribute" | |
> | |
<!-- just copy it! --> | |
<copy-of select="."/> | |
</template> | |
<template mode="only_attributes" | |
match="*" | |
> | |
<variable name="new_children"> | |
<choose> | |
<!-- if an element has multiple kids --> | |
<when test="count(*[not(self::rng:name)]) > 1"> | |
<!-- | |
<message><value-of select="eoa:debug( concat('only_attributes with ', name(), '. multiple kids: ', string-join(*[descendant-or-self::rng:attribute]/name(),', ')))"/></message> | |
--> | |
<copy> | |
<apply-templates mode="only_attributes" select="@*"/> | |
<apply-templates mode="only_attributes" select="*[descendant-or-self::rng:attribute] | text()"/> | |
</copy> | |
</when> | |
<!-- if an element has <= 1 kids --> | |
<otherwise> | |
<!-- | |
<message><value-of select="eoa:debug( concat('only_attributes with ', name(), '. single kid: ', string-join(*[not(self::rng:ref)]/name(), ', ')))"/></message> | |
--> | |
<copy> | |
<apply-templates mode="only_attributes" select="@*"/> | |
<apply-templates mode="only_attributes" select="*[not(self::rng:ref or self::rng:oneOrMore or self::rng:zeroOrMore)] | text()"/> | |
</copy> | |
</otherwise> | |
</choose> | |
</variable> | |
<choose> | |
<when test="self::rng:element and count($new_children/*/*[not(self::rng:name or self::rng:text)]) = 0"> | |
<copy> | |
<rng:empty/> | |
</copy> | |
</when> | |
<when test="(self::rng:group or self::rng:choice) and (count($new_children/*/*) = 0 or count($new_children/*/*[not(self::rng:empty)]) = 0)"> | |
<rng:empty/> | |
</when> | |
<otherwise> | |
<copy-of select="$new_children/*"/> | |
</otherwise> | |
</choose> | |
</template> | |
<template mode="only_attributes" match="@*"> | |
<copy/> | |
<!-- | |
<copy> | |
<apply-templates mode="no_attributes" select="node() | @*"/> | |
</copy> | |
--> | |
</template> | |
<template mode="resolve_paths" match="eoa:path"> | |
<param name="definitions_root"/> | |
<copy> | |
<apply-templates mode="resolve_paths_entry" select="eoa:entry"> | |
<with-param name="definitions_root" select="$definitions_root"/> | |
</apply-templates> | |
</copy> | |
</template> | |
<template mode="resolve_paths_entry" match="eoa:entry"> | |
<param name="definitions_root"/> | |
<variable name="this" select="."/> | |
<copy> | |
<variable name="definition" select="$definitions_root//eoa:define[rng:define/@name = $this/text()]"/> | |
<variable name="resolved"> | |
<choose> | |
<when test="$definition/eoa:unique_xpath_expr_simple"> | |
<value-of select="$definition/eoa:unique_xpath_expr_simple"/> | |
</when> | |
<otherwise> | |
<value-of select="$definition/../../@name"/> | |
</otherwise> | |
</choose> | |
</variable> | |
<value-of select="$resolved"/> | |
<if test="eoa:but_not"> | |
<!-- append resolved eoa:but_not entries --> | |
<for-each select="eoa:but_not"> | |
<variable name="definition" select="$definitions_root//eoa:define[rng:define/@name = current()]"/> | |
<copy> | |
<choose> | |
<when test="$definition/eoa:unique_xpath_expr_simple"> | |
<value-of select="$definition/eoa:unique_xpath_expr_simple"/> | |
</when> | |
<otherwise> | |
<value-of select="$definition/../../@name"/> | |
</otherwise> | |
</choose> | |
</copy> | |
</for-each> | |
<!-- | |
<text>[</text> | |
<for-each select="eoa:but_not"> | |
<variable name="definition" select="$definitions_root//eoa:define[rng:define/@name = current()]"/> | |
<text>not(self::</text> | |
<choose> | |
<when test="$definition/eoa:unique_xpath_expr_simple"> | |
<value-of select="$definition/eoa:unique_xpath_expr_simple"/> | |
</when> | |
<otherwise> | |
<value-of select="$definition/../../@name"/> | |
</otherwise> | |
</choose> | |
<text>)</text> | |
<if test="position() != last()"> | |
<text> and </text> | |
</if> | |
</for-each> | |
<text>]</text> | |
--> | |
</if> | |
</copy> | |
</template> | |
<!-- default template: copy everything --> | |
<template mode="resolve_paths" match="@* | node()"> | |
<param name="definitions_root"/> | |
<copy> | |
<apply-templates mode="resolve_paths" select="@*|node()"> | |
<with-param name="definitions_root" select="$definitions_root"/> | |
</apply-templates> | |
</copy> | |
</template> | |
</stylesheet> |