You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@forrest.apache.org by Jeff Turner <je...@apache.org> on 2003/06/08 06:03:39 UTC

Re: Question: adding formatting for 'xml' conent of source element

On Sat, Jun 07, 2003 at 03:29:09AM +0200, Mikael Sitruk wrote:
> Hi
> 
> In the document v1.1 DTD there is the 'source' element that permit to
> include "sources" sample in the generated document. 
> I would like to use this tag, to add XML content and to FORMAT it with
> syntax coloring. 
> I've updated the document2xhtml.xsl for formatting XML elements under
> the source element, the XSL works fine, but in order to permit XML
> content under the 'source' element I have to DISABLE the validation of
> the document 1.1 DTD, since the DTD doesn't have the definitions for the
> new XML elements in the source element.
> Note: overriding the DTD for each xml fragment that I want to add,
> doesn't seems to be realistic.
> 
> If I put the CDATA declaration, I do pass the validation but the syntax
> coloring is not working. 
> Do someone have an idea how I can include this XML content, and still be
> able to format it??

Colourizing <source> contents is somewhere on the "cool features to add"
list.  We want to be able to colourize anything, not just XML, so there'd
need to be a 'type' attribute:

<source type="Java">
  public static void main(String args[]) {
      System.out.println("Hello world");
  }
</source>

<source type="XML">
  <foo>
    <bar/>
  </foo>
</source>


I think the best way to implement this is to use the Chaperon parser to
translate the <source> contents to HTML.  The Cocoon samples have a demo
of colourizing Java code, and Forrest already includes Chaperon for the
Wiki parsing, so everything that's needed (except grammars) should be
there.

--Jeff


> Thanks
> Mikael.S

RE: Question: adding formatting for 'xml' conent of source element

Posted by Mikael Sitruk <mi...@bezeqint.net>.
Yes that what I did already.
I've perhaps a solution:
I will store the xml sample in a separate file an load them only in XSL
processing.
Detail:
I will add to the source element the 'uri' or 'external-file-name'
attribute (I've also added the type, e.g. xml, java...). In this
attribute I will store either the uri or the file name of a file
containing only the sample of the xml that need to be formatted.
In XSL when getting to the source element I will load the nodes in the
external-file (using the document() function), then do the formatting.
In this way I think I will pass the validation, since source element
will not violate the DTD.

I will inform you...
Mikael.S
-----Original Message-----
From: Jeff Turner [mailto:jefft@apache.org] 
Sent: Monday, June 09, 2003 04:25
To: forrest-dev@xml.apache.org
Subject: Re: Question: adding formatting for 'xml' conent of source
element

On Sun, Jun 08, 2003 at 11:27:10PM +0200, Mikael Sitruk wrote:
> Jeff hi 
> 
> I've already tried this, but the ANY declaration tells the XML
validator
> that ANY of the declared element in the DTD is legal. I can't override
> the DTD for each of the xml samples I want to add, it will be a
> nightmare.

Hmm, then I guess there isn't really any solution other than to switch
off DTD validation, by setting 'forrest.validate.xdocs=false' in
forrest.properties.

--Jeff


Re: Question: adding formatting for 'xml' conent of source element

Posted by Jeff Turner <je...@apache.org>.
On Sun, Jun 08, 2003 at 11:27:10PM +0200, Mikael Sitruk wrote:
> Jeff hi 
> 
> I've already tried this, but the ANY declaration tells the XML validator
> that ANY of the declared element in the DTD is legal. I can't override
> the DTD for each of the xml samples I want to add, it will be a
> nightmare.

Hmm, then I guess there isn't really any solution other than to switch
off DTD validation, by setting 'forrest.validate.xdocs=false' in
forrest.properties.

--Jeff

RE: Question: adding formatting for 'xml' conent of source element

Posted by David Crossley <cr...@indexgeo.com.au>.
Mikael Sitruk wrote:
> David hi
> 
> The <source><![CDATA[ - is not working, since the element inside are not
> interpreted as element!
> For example:
> <source><![CDATA[
> <function name="AA">
> dsdsd
> </function>
> ]]>
> </source>
> 
> In XSL: 
> <xsl:template match="source">
> <xsl:value-of select="function"/>
> </xsl:template>
> 
> This will return nothing since the XML processor doesn't understand the
> CDATA content as XML but as string.


I understand now, thanks.

This is just a wild guess, but i wonder if the Chaperon parser will be of help.
See the examples in cocoon-2.1 and the documentation at chaperon.sf.net
Chaperon is shipped with Forrest - i think that the cwiki pipelines use it.

--David



RE: Question: adding formatting for 'xml' conent of source element

Posted by Mikael Sitruk <mi...@bezeqint.net>.
David hi

The <source><![CDATA[ - is not working, since the element inside are not
interpreted as element!
For example:
<source><![CDATA[
<function name="AA">
dsdsd
</function>
]]>
</source>

In XSL: 
<xsl:template match="source">
<xsl:value-of select="function"/>
</xsl:template>

This will return nothing since the XML processor doesn't understand the
CDATA content as XML but as string.

If I do the formatting prior e.g. in external document, then run an XSL
to get to a document that validate the document-v11.dtd, using the CDATA
then the processor will send the content of the XML to the HTML but the
formatting will not be interpreted as HTML tag:
Example:
<source><![CDATA[<font color="blue">&lt;</font>function name="AA" &gt;
.....
...
]]>
</source>

In XSL: 
<xsl:template match="source">
>xsl:value-of select="."/>
</xsl:template<

will show in the browser:
<font color="blue">&lt;</font>function name="AA" &gt; .....
and not <function name="AA"> where the "<" is in blue.
I've also tried the disable-output-escaping, it doesn't seems to work.

If there is a function to translate the xml string to xml node it may
help, but I don't know such one, exept if the xml is stored in a
separate file, and that what I will try...

Mikael.S


-----Original Message-----
From: David Crossley [mailto:crossley@indexgeo.com.au] 
Sent: Monday, June 09, 2003 04:30
To: forrest-dev@xml.apache.org
Subject: RE: Question: adding formatting for 'xml' conent of source
element

Mikael Sitruk wrote:
> Jeff hi 
> 
> I've already tried this, but the ANY declaration tells the XML
validator
> that ANY of the declared element in the DTD is legal. I can't override
> the DTD for each of the xml samples I want to add, it will be a
> nightmare.

Can we go back to discussing using <source><![CDATA[ ... in the xml
instance.
Why does that cause you a problem with later processing? Perhaps we are
trying
to solve the wrong issue.

--David



RE: Question: adding formatting for 'xml' conent of source element

Posted by David Crossley <cr...@indexgeo.com.au>.
Mikael Sitruk wrote:
> Jeff hi 
> 
> I've already tried this, but the ANY declaration tells the XML validator
> that ANY of the declared element in the DTD is legal. I can't override
> the DTD for each of the xml samples I want to add, it will be a
> nightmare.

Can we go back to discussing using <source><![CDATA[ ... in the xml instance.
Why does that cause you a problem with later processing? Perhaps we are trying
to solve the wrong issue.

--David



RE: Question: adding formatting for 'xml' conent of source element

Posted by Mikael Sitruk <mi...@bezeqint.net>.
Jeff hi 

I've already tried this, but the ANY declaration tells the XML validator
that ANY of the declared element in the DTD is legal. I can't override
the DTD for each of the xml samples I want to add, it will be a
nightmare.



-----Original Message-----
From: Jeff Turner [mailto:jefft@apache.org] 
Sent: Sunday, June 08, 2003 07:50
To: forrest-dev@xml.apache.org
Subject: Re: Question: adding formatting for 'xml' conent of source
element

On Sun, Jun 08, 2003 at 07:17:32AM +0200, Mikael Sitruk wrote:
> Jeff hi
> 
> The formatting/colorizing is not problem since I have already done the
> color and I have also added the type attribute on the source element.
> The real problem is that the source element in the DTD does NOT allow
> any element in it. So each time I put XML elements there I get
> validation error.

That's the symptom of doing it the wrong way :)  But anyway, I think it
can be done by overriding the DTD as described at:

http://xml.apache.org/forrest/validation.html

And redefining the 'source' attribute as:

<!ELEMENT source ANY>

--Jeff

> 
> Mikael.S


Re: Question: adding formatting for 'xml' conent of source element

Posted by Jeff Turner <je...@apache.org>.
On Sun, Jun 08, 2003 at 07:17:32AM +0200, Mikael Sitruk wrote:
> Jeff hi
> 
> The formatting/colorizing is not problem since I have already done the
> color and I have also added the type attribute on the source element.
> The real problem is that the source element in the DTD does NOT allow
> any element in it. So each time I put XML elements there I get
> validation error.

That's the symptom of doing it the wrong way :)  But anyway, I think it
can be done by overriding the DTD as described at:

http://xml.apache.org/forrest/validation.html

And redefining the 'source' attribute as:

<!ELEMENT source ANY>

--Jeff

> 
> Mikael.S

RE: Question: adding formatting for 'xml' conent of source element

Posted by Mikael Sitruk <mi...@bezeqint.net>.
Jeff hi

The formatting/colorizing is not problem since I have already done the
color and I have also added the type attribute on the source element.
The real problem is that the source element in the DTD does NOT allow
any element in it. So each time I put XML elements there I get
validation error.

For example:
<source type="xml" xmlns:xsi="http://www.w3.org/2001/XMLSchema">
<field xsi:type="transformation-data-object-field-t" name="Reason
Headline" type="string" visible="true" description="set the backout
reason as headling">
  <source-function>
    <operand>
      <extension-function xsi:type="title-case-t" name="title-case"
class="amdocs.et.expression.implementations.builtinfunctions.TitleCase">
        <built-in-function-parameter>
          <operand>
            <value-ref xsi:type="data-object-field-reference-t"
data-object-id="Backout_Reason" field-name="Reason Desc"/>
          </operand>
        </built-in-function-parameter>
      </extension-function>
    </operand>
  </source-function>
</field>
</source>

Will not pass the validation since the elements: fields,
source-function, operand, extension-function,
built-in-function-parameter are not defined in the DTD.
Since the xml fragments are very heterogeneous and not comes from the
same schema I can't update the DTD each time I want to add an XML
sample. 
Since the sample source is XML I think that the easiest way is to use
XSL to do the formatting, that's true that for other language chaperon
may be the best fit, but for the current problem I think that XSL is
enough. The only problem still remain to pass the XML validation....
Anyway I will also check your suggestion...

Mikael.S


-----Original Message-----
From: Jeff Turner [mailto:jefft@apache.org] 
Sent: Sunday, June 08, 2003 06:04
To: forrest-dev@xml.apache.org
Subject: Re: Question: adding formatting for 'xml' conent of source
element

On Sat, Jun 07, 2003 at 03:29:09AM +0200, Mikael Sitruk wrote:
> Hi
> 
> In the document v1.1 DTD there is the 'source' element that permit to
> include "sources" sample in the generated document. 
> I would like to use this tag, to add XML content and to FORMAT it with
> syntax coloring. 
> I've updated the document2xhtml.xsl for formatting XML elements under
> the source element, the XSL works fine, but in order to permit XML
> content under the 'source' element I have to DISABLE the validation of
> the document 1.1 DTD, since the DTD doesn't have the definitions for
the
> new XML elements in the source element.
> Note: overriding the DTD for each xml fragment that I want to add,
> doesn't seems to be realistic.
> 
> If I put the CDATA declaration, I do pass the validation but the
syntax
> coloring is not working. 
> Do someone have an idea how I can include this XML content, and still
be
> able to format it??

Colourizing <source> contents is somewhere on the "cool features to add"
list.  We want to be able to colourize anything, not just XML, so
there'd
need to be a 'type' attribute:

<source type="Java">
  public static void main(String args[]) {
      System.out.println("Hello world");
  }
</source>

<source type="XML">
  <foo>
    <bar/>
  </foo>
</source>


I think the best way to implement this is to use the Chaperon parser to
translate the <source> contents to HTML.  The Cocoon samples have a demo
of colourizing Java code, and Forrest already includes Chaperon for the
Wiki parsing, so everything that's needed (except grammars) should be
there.

--Jeff


> Thanks
> Mikael.S