Question

I want to know whether it is possible to transform Relax NG XML with XSLT. Please give me some tutorial.

I don't seem to be able to match the grammar-tag in the RelaxNG schema below with <xsl:template match="grammar">

<grammar>

  <start>
    <element name="html">
      <zeroOrMore>
        <ref name="section"/>
      </zeroOrMore>
    </element>
  </start>

  <define name="section">
    <element name="div">
      <attribute name="class"><value>section</value></attribute>
      <zeroOrMore>
        <element name="para">
          <text/>
        </element>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="subsection"/>
      </zeroOrMore>
   </element>
  </define>



</grammar>
Was it helpful?

Solution

Relax NG is a language for expressing a grammar of XML. W3C XML Schema is also such a language. XSLT however, is a language of transforming XML into another data format. In other words, they cover different grounds. Do you really mean to convert Relax NG into XSLT?

You find quite some XSLT's that you can use to optimize, transform etc your Relax NG, DTD or XML Schema to / from each other on the Relax NG homepage.

Just guessing: you might actually be after is a tool to validate existing XML by its Relax NG schema. You can do that with any one of the validators.

EDIT, based on your last comment. The reason that your xsl:template isn't hit is most likely because you didn't specify the RelaxNG namespace. You didn't show any of your code, but try to apply something like the following to your stylesheet (note that the namespace prefix doesn't matter and doesn't need to be in the source XML document):

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:ng="http://relaxng.org/ns/structure/1.0">

    <xsl:template match="ng:grammar">
        <xsl:text>Grammar found!</xsl:text>
    </xsl:template>
</xsl:stylesheet>

OTHER TIPS

Do you mean, can I compile a Relax NG schema into an XSLT stylesheet that performs the validation implied by the schema?

The answer is, yes, theoretically you can, if you have a good understanding of the computer science theory of (a) how to convert a BNF grammar to a finite state automaton, and (b) how to implement a finite state automaton in a functional programming language.

Somehow, though, I suspect that if this is what you wanted to do then you wouldn't have asked the question in the way you did.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top