Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7908469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T11:56:56+00:00 2026-06-03T11:56:56+00:00

I’m trying to generate very simple documentation from the annotations in a Relax NG

  • 0

I’m trying to generate very simple documentation from the annotations in a Relax NG XML Schema. For example, given the following Relax NG:

<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <element name="topNode">
            <ref name="topNode-ref"/>
        </element>
    </start>

    <define name="topNode-ref">
        <a:documentation>This is the top of the doc.</a:documentation>
        <oneOrMore>
            <element name="level1">
                <ref name="level1-ref"/>
            </element>
        </oneOrMore>
    </define>

    <define name="level1-ref">
        <a:documentation>Here's some notes about level1.</a:documentation>
        <attribute name="att1">
            <a:documentation>Details about att1.</a:documentation>
        </attribute>
        <element name="subLevel2">
            <ref name="subLevel2-ref"/>
        </element>
    </define>

    <define name="subLevel2-ref">
        <a:documentation>Notes on subLevel2.</a:documentation>
        <attribute name="subAtt"/>
        <zeroOrMore>
            <element name="subLevel3">
                <ref name="subLevel3-ref"/>
            </element>
        </zeroOrMore>
    </define>

    <define name="subLevel3-ref">
        <a:documentation>And here is subLevel3.</a:documentation>
        <attribute name="subSubAtt"/>
    </define>
</grammar>

Which would be used to valid an XML file like:

<?xml version="1.0" encoding="UTF-8"?>
<topNode>
    <level1 att1="some test">
        <subLevel2 subAtt="more text"></subLevel2>
    </level1>

    <level1 att1="quick">
        <subLevel2 subAtt="brown">
            <subLevel3 subSubAtt="fox"></subLevel3>
        </subLevel2>
    </level1>   
</topNode>

I’d like to be able to produce documentation that lists the basic XPath to each element/attribute and then display any corresponding documentation annotations. For example:

/topNode
This is the top of the doc.

/topNode/level1
Here's some notes about level1

/topNode/level1/@att1
Details about att1.

etc...

Eventually, I’ll add in more documentation about “zeroOrMore”, possible data types, etc… but I need to get this first step solved first.

I’ve found the Techquila RELAX-NG Documentation Tools. I’ve played around with the rng to docbook stylesheet, but it don’t do what I’m looking for. It just lists elements individually with no details about the XPath as far as I can tell. I don’t see how I can use it as a starting point to get the output I’m after.

Is it possible (and if so, how?) to produce this type of documentation output with XSLT given the RelaxNG example provided?

While XSLT would be ideal, it’s not a requirement. I’m open for anything that gets the job done.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T11:57:00+00:00Added an answer on June 3, 2026 at 11:57 am

    This will work for a very simple grammar like your example.

    <?xml version='1.0'?>
    <xsl:stylesheet version="1.0" 
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:r="http://relaxng.org/ns/structure/1.0" 
        xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
    >
    <xsl:output method="text" />
    
    <xsl:template match="/">
        <xsl:apply-templates select="//r:define[a:documentation] | //r:attribute[a:documentation]" />
    </xsl:template>
    
    <xsl:template match="r:define">
        <xsl:variable name="doc" select="a:documentation" />
        <xsl:call-template name="print-path">
            <xsl:with-param name="elm" select="//r:element[r:ref/@name=current()/@name]" />
        </xsl:call-template>
        <xsl:value-of select="$doc" /><xsl:text>&#10;</xsl:text>
    </xsl:template>
    
    <xsl:template match="r:attribute">
        <xsl:variable name="doc" select="a:documentation" />
        <xsl:call-template name="print-path">
            <xsl:with-param name="elm" select="//r:element[r:ref/@name=current()/ancestor::r:define/@name]" />
            <xsl:with-param name="path" select="concat('/@',@name)" />
        </xsl:call-template>
        <xsl:value-of select="$doc" /><xsl:text>&#10;</xsl:text>
    </xsl:template>
    
    <xsl:template name="print-path">
        <xsl:param name="elm" />
        <xsl:param name="path" />
    
        <xsl:variable name="parent" select="//r:ref[@name=$elm/ancestor::r:define/@name]/ancestor::r:element" />
        <xsl:message><xsl:value-of select="$elm/@name" /></xsl:message>
        <xsl:choose>
            <xsl:when test="$parent">
                <xsl:call-template name="print-path">
                    <xsl:with-param name="elm" select="$parent" />
                    <xsl:with-param name="path" select="concat('/',$elm/@name,$path)" />
                </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="concat('/',$elm/@name,$path)" /><xsl:text>&#10;</xsl:text>            
            </xsl:otherwise>
        </xsl:choose>
    </xsl:template>
    
    </xsl:stylesheet>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am doing a simple coin flipping experiment for class that involves flipping a
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.