Commits

Shlomi Fish committed 77f31b6

Add the Vered-XML files.

  • Participants
  • Parent commits 192e999

Comments (0)

Files changed (2)

XML-Grammar-Vered/extradata/vered-xml-to-docbook.xslt

+<?xml version="1.0" encoding="UTF-8"?>
+<xsl:stylesheet version = '1.0'
+    xmlns:xsl='http://www.w3.org/1999/XSL/Transform'
+    xmlns:vrd="http://www.shlomifish.org/open-source/projects/XML-Grammar/Vered/"
+    xmlns="http://docbook.org/ns/docbook"
+    xmlns:db="http://docbook.org/ns/docbook"
+    xmlns:xlink="http://www.w3.org/1999/xlink">
+
+<xsl:output method="xml" encoding="UTF-8" indent="yes"
+ />
+
+<xsl:template match="/vrd:document">
+    <db:article>
+        <xsl:if test="@xml:id">
+            <xsl:attribute name="xml:id">
+                <xsl:value-of select="@xml:id" />
+            </xsl:attribute>
+        </xsl:if>
+        <xsl:attribute name="xml:lang">
+            <xsl:value-of select="@xml:lang" />
+        </xsl:attribute>
+        <xsl:attribute name="version">5.0</xsl:attribute>
+        <db:info>
+            <db:title>
+                <xsl:value-of select="vrd:info/vrd:title" />
+            </db:title>
+        </db:info>
+        <xsl:apply-templates select="vrd:body/vrd:preface" />
+        <xsl:apply-templates select="vrd:body/vrd:section" />
+    </db:article>
+</xsl:template>
+
+<xsl:template match="vrd:preface">
+    <db:section role="introduction">
+        <xsl:call-template name="preface_or_section" />
+    </db:section>
+</xsl:template>
+
+<xsl:template name="preface_or_section">
+    <xsl:copy-of select="@xml:id" />
+    <xsl:if test="@xml:lang">
+        <xsl:copy-of select="@xml:lang" />
+    </xsl:if>
+    <db:info>
+        <db:title>
+            <xsl:choose>
+                <xsl:when test="vrd:info/vrd:title">
+                    <xsl:value-of select="vrd:info/vrd:title" />
+                </xsl:when>
+                <xsl:otherwise>
+                    <xsl:value-of select="@xml:id" />
+                </xsl:otherwise>
+            </xsl:choose>
+        </db:title>
+    </db:info>
+    <xsl:apply-templates select="vrd:section|vrd:blockquote|vrd:p|vrd:ol|vrd:ul|vrd:programlisting|vrd:item" />
+</xsl:template>
+
+<xsl:template match="vrd:section">
+    <db:section>
+        <xsl:call-template name="preface_or_section" />
+    </db:section>
+</xsl:template>
+
+<xsl:template match="vrd:item">
+    <db:section role="item">
+        <xsl:call-template name="common_attributes" />
+        <!-- TODO : extract this db:info thing into a common named
+        xsl:template. -->
+        <db:info>
+            <db:title>
+                <xsl:choose>
+                    <xsl:when test="vrd:info/vrd:title">
+                        <xsl:value-of select="vrd:info/vrd:title" />
+                    </xsl:when>
+                    <xsl:otherwise>
+                        <xsl:value-of select="@xml:id" />
+                    </xsl:otherwise>
+                </xsl:choose>
+            </db:title>
+        </db:info>
+        <xsl:apply-templates select="vrd:blockquote|vrd:p|vrd:ol|vrd:ul|vrd:programlisting|vrd:code_blk|vrd:bad_code" />
+        <xsl:apply-templates select="vrd:item" />
+    </db:section>
+</xsl:template>
+
+<xsl:template match="vrd:bad_code">
+    <db:programlisting xml:space="preserve" role="bad_code">
+        <xsl:attribute name="language">
+            <xsl:value-of select="@syntax" />
+        </xsl:attribute>
+        <xsl:text># Bad code
+
+</xsl:text>
+        <xsl:apply-templates/>
+    </db:programlisting>
+</xsl:template>
+
+<xsl:template match="vrd:code_blk">
+    <db:programlisting xml:space="preserve">
+        <xsl:attribute name="language">
+            <xsl:value-of select="@syntax" />
+        </xsl:attribute>
+        <xsl:apply-templates/>
+    </db:programlisting>
+</xsl:template>
+
+<xsl:template match="vrd:p">
+    <db:para>
+        <xsl:apply-templates />
+    </db:para>
+</xsl:template>
+
+<xsl:template match="vrd:b|vrd:strong">
+    <db:emphasis role="bold">
+        <xsl:apply-templates/>
+    </db:emphasis>
+</xsl:template>
+
+<xsl:template name="common_attributes">
+    <xsl:if test="@xlink:href">
+        <xsl:copy-of select="@xlink:href" />
+    </xsl:if>
+    <xsl:if test="@xml:lang">
+        <xsl:copy-of select="@xml:lang" />
+    </xsl:if>
+    <xsl:if test="@xml:id">
+        <xsl:copy-of select="@xml:id" />
+    </xsl:if>
+</xsl:template>
+
+<xsl:template match="vrd:blockquote">
+    <db:blockquote>
+        <xsl:call-template name="common_attributes" />
+        <xsl:apply-templates/>
+    </db:blockquote>
+</xsl:template>
+
+<xsl:template match="vrd:i|vrd:em">
+    <db:emphasis>
+        <xsl:apply-templates/>
+    </db:emphasis>
+</xsl:template>
+
+<xsl:template match="vrd:code">
+    <db:code>
+        <xsl:apply-templates/>
+    </db:code>
+</xsl:template>
+
+<xsl:template match="vrd:pdoc">
+    <xsl:variable name="d">
+        <xsl:value-of select="@d" />
+    </xsl:variable>
+    <db:link role="perldoc">
+        <xsl:attribute name="xlink:href">
+            <xsl:text>http://perldoc.perl.org/</xsl:text>
+            <xsl:value-of select="$d" />
+            <xsl:text>.html</xsl:text>
+        </xsl:attribute>
+        <xsl:value-of select="$d" />
+        <xsl:apply-templates/>
+    </db:link>
+</xsl:template>
+
+<xsl:template match="vrd:pdoc_f">
+    <xsl:variable name="f">
+        <xsl:value-of select="@f" />
+    </xsl:variable>
+    <db:link role="perldoc_func">
+        <xsl:attribute name="xlink:href">
+            <xsl:text>http://perldoc.perl.org/functions/</xsl:text>
+            <xsl:value-of select="$f" />
+            <xsl:text>.html</xsl:text>
+        </xsl:attribute>
+        <xsl:apply-templates/>
+    </db:link>
+</xsl:template>
+
+<xsl:template match="vrd:cpan_mod">
+    <db:link role="cpan_module">
+        <xsl:attribute name="xlink:href">
+            <xsl:text>http://metacpan.org/module/</xsl:text>
+            <xsl:value-of select="@m" />
+        </xsl:attribute>
+        <xsl:apply-templates/>
+    </db:link>
+</xsl:template>
+
+<xsl:template match="vrd:cpan_self_mod">
+    <xsl:variable name="module">
+        <xsl:value-of select="@m" />
+    </xsl:variable>
+    <db:link role="cpan_module">
+        <xsl:attribute name="xlink:href">
+            <xsl:text>http://metacpan.org/module/</xsl:text>
+            <xsl:value-of select="$module" />
+        </xsl:attribute>
+        <xsl:value-of select="$module" />
+    </db:link>
+</xsl:template>
+
+<xsl:template match="vrd:cpan_self_dist">
+    <xsl:variable name="dist">
+        <xsl:value-of select="@d" />
+    </xsl:variable>
+    <db:link role="cpan_dist">
+        <xsl:attribute name="xlink:href">
+            <xsl:text>http://metacpan.org/release/</xsl:text>
+            <xsl:value-of select="$dist" />
+        </xsl:attribute>
+        <xsl:value-of select="$dist" />
+    </db:link>
+</xsl:template>
+
+<xsl:template match="vrd:filepath">
+    <db:filename>
+        <xsl:apply-templates/>
+    </db:filename>
+</xsl:template>
+
+<xsl:template match="vrd:ol">
+    <db:orderedlist>
+        <xsl:apply-templates/>
+    </db:orderedlist>
+</xsl:template>
+
+<xsl:template match="vrd:ul">
+    <db:itemizedlist>
+        <xsl:apply-templates/>
+    </db:itemizedlist>
+</xsl:template>
+
+<xsl:template match="vrd:programlisting">
+    <db:programlisting>
+        <xsl:apply-templates/>
+    </db:programlisting>
+</xsl:template>
+
+<xsl:template match="vrd:li">
+    <db:listitem>
+        <xsl:apply-templates/>
+    </db:listitem>
+</xsl:template>
+
+<xsl:template match="vrd:a">
+    <xsl:element name="db:link">
+        <xsl:call-template name="common_attributes" />
+        <xsl:apply-templates/>
+    </xsl:element>
+</xsl:template>
+
+<xsl:template match="vrd:span">
+    <xsl:variable name="tag_name">
+        <xsl:choose>
+            <xsl:when test="@xlink:href">
+                <xsl:value-of select="'db:link'" />
+            </xsl:when>
+            <xsl:otherwise>
+                <xsl:value-of select="'db:phrase'" />
+            </xsl:otherwise>
+        </xsl:choose>
+    </xsl:variable>
+    <xsl:element name="{$tag_name}">
+        <xsl:call-template name="common_attributes" />
+        <xsl:apply-templates/>
+    </xsl:element>
+</xsl:template>
+
+</xsl:stylesheet>

XML-Grammar-Vered/extradata/vered-xml.rng

+<?xml version="1.0" encoding="UTF-8"?>
+<!-- $Id: testSuite.rng,v 1.12 2003/01/29 12:24:07 jjc Exp $ -->
+<grammar xmlns="http://relaxng.org/ns/structure/1.0"
+    xmlns:vrd="http://www.shlomifish.org/open-source/projects/XML-Grammar/Vered/"
+    xmlns:xlink="http://www.w3.org/1999/xlink"
+    datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
+    >
+    <start>
+        <element name="vrd:document">
+            <ref name="common_attrs" />
+            <attribute name="version">
+                <text />
+            </attribute>
+            <ref name="info" />
+            <element name="vrd:body">
+                <ref name="common_attrs" />
+                <zeroOrMore>
+                    <element name="vrd:preface">
+                        <ref name="section_contents" />
+                    </element>
+                </zeroOrMore>
+                <oneOrMore>
+                    <ref name="section" />
+                </oneOrMore>
+            </element>
+        </element>
+    </start>
+    <define name="global_attrs">
+        <optional>
+            <attribute name="xml:id">
+                <data type="ID"/>
+            </attribute>
+        </optional>
+        <optional>
+            <attribute name="xml:lang">
+                <data type="NCName" />
+            </attribute>
+        </optional>
+    </define>
+    <define name="common_attrs">
+        <ref name="global_attrs" />
+        <optional>
+            <attribute name="xlink:href">
+                <data type="anyURI"/>
+            </attribute>
+        </optional>
+    </define>
+    <define name="section_contents">
+        <ref name="global_attrs" />
+        <ref name="info" />
+        <ref name="several_paras" />
+        <zeroOrMore>
+            <ref name="section" />
+        </zeroOrMore>
+    </define>
+    <define name="section">
+        <element name="vrd:section">
+            <ref name="global_attrs" />
+            <ref name="info" />
+            <ref name="several_paras" />
+            <ref name="some_items" />
+            <zeroOrMore>
+                <ref name="section" />
+            </zeroOrMore>
+        </element>
+    </define>
+    <define name="some_items">
+        <zeroOrMore>
+            <ref name="item" />
+        </zeroOrMore>
+    </define>
+    <define name="item">
+        <element name="vrd:item">
+            <ref name="global_attrs" />
+            <ref name="info" />
+            <ref name="several_paras" />
+            <ref name="some_items" />
+        </element>
+    </define>
+    <define name="several_paras">
+        <zeroOrMore>
+            <choice>
+                <ref name="blockquote"/>
+                <ref name="p"/>
+                <ref name="ol"/>
+                <ref name="ul"/>
+                <ref name="programlisting"/>
+                <ref name="bad_code"/>
+                <ref name="code_blk"/>
+            </choice>
+        </zeroOrMore>
+    </define>
+    <define name="inside_list">
+        <oneOrMore>
+            <ref name="li" />
+        </oneOrMore>
+    </define>
+    <define name="ol">
+        <element name="vrd:ol">
+            <ref name="inside_list" />
+        </element>
+    </define>
+    <define name="ul">
+        <element name="vrd:ul">
+            <ref name="inside_list" />
+        </element>
+    </define>
+    <define name="blockquote">
+        <element name="vrd:blockquote">
+            <ref name="common_attrs" />
+            <ref name="several_paras"/>
+        </element>
+    </define>
+    <define name="li">
+        <element name="vrd:li">
+            <oneOrMore>
+                <ref name="p" />
+            </oneOrMore>
+        </element>
+    </define>
+    <define name="p">
+        <element name="vrd:p">
+            <zeroOrMore>
+                <choice>
+                    <ref name="text_with_style" />
+                    <ref name="span" />
+                    <ref name="a" />
+                </choice>
+            </zeroOrMore>
+        </element>
+    </define>
+    <define name="text_with_style">
+        <choice>
+            <text />
+            <ref name="b" />
+            <ref name="i" />
+            <element name="vrd:cpan_self_dist">
+                <attribute name="d">
+                    <text />
+                </attribute>
+                <empty />
+            </element>
+            <element name="vrd:cpan_self_mod">
+                <attribute name="m">
+                    <text />
+                </attribute>
+                <empty />
+            </element>
+            <element name="vrd:cpan_mod">
+                <attribute name="m">
+                    <text />
+                </attribute>
+                <text />
+            </element>
+            <element name="vrd:pdoc">
+                <attribute name="d">
+                    <text />
+                </attribute>
+                <text />
+            </element>
+            <element name="vrd:pdoc_f">
+                <attribute name="f">
+                    <text />
+                </attribute>
+                <text />
+            </element>
+            <element name="vrd:strong">
+                <text />
+            </element>
+            <element name="vrd:em">
+                <text />
+            </element>
+            <element name="vrd:code">
+                <text />
+            </element>
+            <element name="vrd:filepath">
+                <text />
+            </element>
+        </choice>
+    </define>
+    <define name="span">
+        <element name="vrd:span">
+            <ref name="common_attrs" />
+            <oneOrMore>
+                <ref name="text_with_style" />
+            </oneOrMore>
+        </element>
+    </define>
+    <define name="a">
+        <element name="vrd:a">
+            <ref name="global_attrs" />
+            <attribute name="xlink:href">
+                <data type="anyURI"/>
+            </attribute>
+            <oneOrMore>
+                <ref name="text_with_style" />
+            </oneOrMore>
+        </element>
+    </define>
+    <define name="b">
+        <element name="vrd:b">
+            <text />
+        </element>
+    </define>
+    <define name="i">
+        <element name="vrd:i">
+            <text />
+        </element>
+    </define>
+    <define name="title">
+        <element name="vrd:title">
+            <text />
+        </element>
+    </define>
+    <define name="code_contents">
+        <ref name="common_attrs" />
+        <attribute name="syntax">
+            <text/>
+        </attribute>
+        <text/>
+    </define>
+    <define name="bad_code">
+        <element name="vrd:bad_code">
+            <ref name="code_contents" />
+        </element>
+    </define>
+    <define name="code_blk">
+        <element name="vrd:code_blk">
+            <ref name="code_contents" />
+        </element>
+    </define>
+    <define name="programlisting">
+        <element name="vrd:programlisting">
+            <ref name="code_contents" />
+        </element>
+    </define>
+    <define name="info">
+        <element name="vrd:info">
+            <ref name="title" />
+        </element>
+    </define>
+</grammar>