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/common/rng_to_rnc.xsl
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
246 lines (221 sloc)
6.82 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"?> | |
<!-- serialize rng->rnc --> | |
<stylesheet version="2.0" | |
xmlns="http://www.w3.org/1999/XSL/Transform" | |
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:fcn="fcn" | |
xmlns:null="null" | |
exclude-result-prefixes="rng fcn xs null eoa" | |
> | |
<!-- | |
<import href="utils.xsl"/> | |
--> | |
<!-- *************************** --> | |
<!-- rng_to_rnc --> | |
<!-- serialize to Relax-NG Compact synatx --> | |
<!-- *************************** --> | |
<template mode="rng_to_rnc" match="rng:grammar"> | |
<param name="indent" select="''"/> | |
<text>grammar { </text> | |
<value-of select="$newline"/> | |
<for-each select="*"> | |
<apply-templates mode="rng_to_rnc" select="."> | |
<with-param name="indent" select="concat($indent,' ')"/> | |
</apply-templates> | |
<value-of select="$newline"/> | |
</for-each> | |
<text>}</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:start"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>start = </text> | |
<apply-templates mode="rng_to_rnc"/> | |
</template> | |
<template mode="rng_to_rnc" match="rng:define"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<value-of select="@name"/> | |
<text> =</text> | |
<value-of select="$newline"/> | |
<apply-templates mode="rng_to_rnc"> | |
<with-param name="indent" select="concat($indent,' ')"/> | |
</apply-templates> | |
</template> | |
<template mode="rng_to_rnc" match="rng:element"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>element </text> | |
<value-of select="rng:name"/> | |
<call-template name="in_curly_brackets"> | |
<with-param name="indent" select="$indent"/> | |
</call-template> | |
</template> | |
<template mode="rng_to_rnc" match="rng:group | rng:choice | rng:interleave"> | |
<param name="indent" select="''"/> | |
<param name="bracket" select="1"/> | |
<variable name="seperator"> | |
<choose> | |
<when test="name() = 'group'"><text>,</text></when> | |
<when test="name() = 'choice'"><text>|</text></when> | |
<when test="name() = 'interleave'"><text>&</text></when> | |
</choose> | |
</variable> | |
<if test="$bracket"> | |
<value-of select="$indent"/> | |
<text>(</text> | |
<value-of select="$newline"/> | |
</if> | |
<variable name="subindent"> | |
<choose> | |
<when test="$bracket"> | |
<value-of select="concat($indent,' ')"/> | |
</when> | |
<otherwise> | |
<value-of select="$indent"/> | |
</otherwise> | |
</choose> | |
</variable> | |
<for-each select="*"> | |
<apply-templates mode="rng_to_rnc" select="."> | |
<with-param name="indent" select="$subindent"/> | |
</apply-templates> | |
<if test="position() != last()"> | |
<value-of select="$seperator"/> | |
<value-of select="$newline"/> | |
</if> | |
</for-each> | |
<if test="$bracket"> | |
<value-of select="$newline"/> | |
<value-of select="$indent"/> | |
<text>)</text> | |
</if> | |
</template> | |
<template mode="rng_to_rnc" match="rng:ref"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<value-of select="@name"/> | |
</template> | |
<template mode="rng_to_rnc" match="rng:attribute"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>attribute </text> | |
<value-of select="rng:name"/> | |
<call-template name="in_curly_brackets"> | |
<with-param name="indent" select="$indent"/> | |
</call-template> | |
</template> | |
<template mode="rng_to_rnc" match="rng:data"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<value-of select="@type"/> | |
</template> | |
<template mode="rng_to_rnc" match="rng:value"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>'</text> | |
<value-of select="."/> | |
<text>'</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:text"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>text</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:empty"> | |
<param name="indent" select="''"/> | |
<value-of select="$indent"/> | |
<text>empty</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:oneOrMore"> | |
<param name="indent" select="''"/> | |
<apply-templates mode="rng_to_rnc"> | |
<with-param name="indent" select="$indent"/> | |
</apply-templates> | |
<text>+</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:zeroOrMore"> | |
<param name="indent" select="''"/> | |
<apply-templates mode="rng_to_rnc"> | |
<with-param name="indent" select="$indent"/> | |
</apply-templates> | |
<text>*</text> | |
</template> | |
<template mode="rng_to_rnc" match="rng:optional"> | |
<param name="indent" select="''"/> | |
<for-each select="*"> | |
<apply-templates mode="rng_to_rnc" select="."> | |
<with-param name="indent" select="$indent"/> | |
</apply-templates> | |
</for-each> | |
<text>?</text> | |
</template> | |
<template mode="rng_to_rnc" match="null:MARK"> | |
<param name="indent" select="''"/> | |
<variable name="result"> | |
<for-each select="*"> | |
<apply-templates mode="rng_to_rnc" select="."> | |
<with-param name="indent" select="$indent"/> | |
</apply-templates> | |
</for-each> | |
</variable> | |
<analyze-string select="$result" regex="."> | |
<matching-substring> | |
<value-of select="."/> | |
<value-of select="$underline"/> | |
</matching-substring> | |
</analyze-string> | |
</template> | |
<!-- default template: copy everything --> | |
<template mode="rng_to_rnc" match="@* | *"> | |
<value-of select="eoa:warning( concat('missing serialization method for ', name()) )"/> | |
<copy> | |
<apply-templates mode="rng_to_rnc" select="@*|node()"/> | |
</copy> | |
</template> | |
<!-- by default: copy text nodes --> | |
<template mode="rng_to_rnc" match="text()"/> | |
<!-- rng_to_rnc utils: --> | |
<template name="in_curly_brackets"> | |
<param name="indent" select="''"/> | |
<choose> | |
<when test="fcn:is_simple(./*[name() != 'name'])"> | |
<text>{ </text> | |
<apply-templates mode="rng_to_rnc" select="*[name() != 'name']"/> | |
<text> }</text> | |
</when> | |
<otherwise> | |
<text>{</text> | |
<value-of select="$newline"/> | |
<apply-templates mode="rng_to_rnc" select="*[name() != 'name']"> | |
<with-param name="indent" select="concat($indent,' ')"/> | |
<with-param name="bracket" select="0"/> | |
</apply-templates> | |
<value-of select="$newline"/> | |
<value-of select="$indent"/> | |
<text>}</text> | |
</otherwise> | |
</choose> | |
</template> | |
<function name="fcn:is_simple" as="xs:boolean"> | |
<param name="p" as="node()+"/> | |
<choose> | |
<when test="$p[name() = 'value' or name() = 'data' or name() = 'text' or name() = 'empty' or name() = 'ref']"> | |
1 | |
</when> | |
<when test="$p[name() = 'oneOrMore' or name() = 'zeroOrMore' or name() = 'optional']"> | |
<value-of select="every $x in $p/element() satisfies fcn:is_simple($x)"/> | |
</when> | |
<!-- TODO: make this work!: | |
<when test="$p[name() = 'group' or name() = 'choice' or name() = 'interleave']"> | |
<value-of select="if (count($p) != 1) then 0 else (every $x in $p/element() satisfies fcn:is_simple($x))"/> | |
</when> | |
--> | |
<otherwise> | |
0 | |
</otherwise> | |
</choose> | |
</function> | |
</stylesheet> |