You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by Martin van den Bemt <ml...@mvdb.net> on 2003/02/01 16:40:09 UTC

[Jelly] Proposal new xml tag xml:entity

Hi everyone,

Was looking at the jsl stuff in maven yesterday and one of the things
that isn't working, is using entities that are not known (logical, but
hey). Since we normally use xml to output stuff, I had an idea of adding
the xml:entity tag. 
it should work like this :
<xml:entity value="copy"/> and this will output &copy; in the document. 
I tried every other thing I could think of to get this parsed
(like &amp;copy; but that resolves just like it is typed, also tried
using CDATA for it, but &copy; resolves to &amp;copy;, etc).

Is it ok to add it ? And is xml the correct taglib to put it in ? 

mvgr,
Martin





---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
> AFAIK enabling the capture of internal DOCTYPEs (which is disabled by
> default) should fix this. e.g. see the extra line I've added...
> 
> 
> >  SAXReader xmlReader = new SAXReader();
> 
> xmlReader.setIncludeInternalDTDDeclarations(true);
> 

I was aware of this, but in fact, I know nothing of the XML documents entering
the pipeline. As I see, it is certainly a bug to read a well-formed XML
document into a DOM4J document model, to make something, to output it,
and to get a result stream not being well-formed. (Partially, my purpose was
to get rid of these SGMLish entities and get bare UTF8. I think that
parsed entities should be replaced on output and if unparsed entities
are present the writer should output the internal subset.)

OTOH I was using dom4j through jelly:xml in a mavenized project. And 
the equivalent of the dom4j code framgment mentioned was something like this:

a.xml:
-
CTYPE a [
<!ENTITY x "y">
]>
<a>&x;</a>
-

part of maven.xml:
-
  <goal name="emnl:test">
    <x:parse var="doc" xml="a.xml"/>
    <echo><x:copyOf select="$doc"/></echo>
  </goal>
-

and this a piece of the output:

-
emnl:test:
    [echo] <?xml version="1.0" encoding="UTF-8"?>
<a>&x;y</a>
BUILD SUCCESSFUL
Total time:  13 seconds
-

/My workaround at the moment is something like this:

-
  <goal name="emnl:test">
    <x:transform var="doc" xslt="identity.xsl" xml="a.xml"/>
    <echo><x:copyOf select="$doc"/></echo>
  </goal>
-

where the identity.xsl is an identity xsl trasformation, and the output is

-
emnl:test:
    [echo] <?xml version="1.0" encoding="UTF-8"?>
<a>y</a>
BUILD SUCCESSFUL
-

as expected. I may be wrong on all of this, but e.g. JDOM behaves this way

            SAXBuilder xmlReader = new SAXBuilder();
            doc = xmlReader.build("a.xml");
            XMLOutputter xmlWriter = new XMLOutputter();
            xmlWriter.output(doc, System.out);

prints the resolved entity, i.e. "y" instead of "&x;"./

Sorry for the long post.

incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by James Strachan <ja...@yahoo.co.uk>.
From: "Incze Lajos" <in...@mail.matav.hu>
> On Mon, Feb 03, 2003 at 09:49:04AM +0100, Martin van den Bemt wrote:
> > So maybe there should be an xml:text tag to get this handled (don't use
> > xslt myself though) ?
> >
> I think it's better to have a <jsl:text> tag that accepts the
> disable-output-escaping="yes" attribute. You don't need any special
> xml tag just output an <entity name="copy"/> tag to the processing
> chain (the xml taglib will output it transparentely), catch it in
> a rule and use the jsl:text tag for it.
>
> One of my major headache right now is that (Don't want to give you
> bad tips, that in a document:
>
> <?xml version="1.0"?>
> <!DOCTYPE a [
> <!ENTITY x "y">
> ]>
> <a>&x;</a>
>
> the dom4j linrary will output (just something like what you want)
>
> <?xml version="1.0" encoding="UTF-8"?>
> <!DOCTYPE a><a>&x;</a>
>
> in a simple read-in/write-out processing (e.g.:

AFAIK enabling the capture of internal DOCTYPEs (which is disabled by
default) should fix this. e.g. see the extra line I've added...


>  SAXReader xmlReader = new SAXReader();

xmlReader.setIncludeInternalDTDDeclarations(true);

> Document doc = xmlReader.read(argv[0]);
> XMLWriter writer = new XMLWriter(System.out);
> writer.write(doc);
> writer.flush();)
>
> which is not well-formed, so my processing pipe breaks at this point.
> At any "creative" solution you 'll find yourself similar problems.

James
-------
http://radio.weblogs.com/0112098/

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
On Mon, Feb 03, 2003 at 09:49:04AM +0100, Martin van den Bemt wrote:
> So maybe there should be an xml:text tag to get this handled (don't use
> xslt myself though) ?
> 
I think it's better to have a <jsl:text> tag that accepts the
disable-output-escaping="yes" attribute. You don't need any special
xml tag just output an <entity name="copy"/> tag to the processing
chain (the xml taglib will output it transparentely), catch it in
a rule and use the jsl:text tag for it.

One of my major headache right now is that (Don't want to give you
bad tips, that in a document:

<?xml version="1.0"?>
<!DOCTYPE a [
<!ENTITY x "y">
]>
<a>&x;</a>

the dom4j linrary will output (just something like what you want)

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE a><a>&x;</a>

in a simple read-in/write-out processing (e.g.:

 SAXReader xmlReader = new SAXReader();
Document doc = xmlReader.read(argv[0]);
XMLWriter writer = new XMLWriter(System.out);
writer.write(doc);
writer.flush();)

which is not well-formed, so my processing pipe breaks at this point.
At any "creative" solution you 'll find yourself similar problems.

incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by James Strachan <ja...@yahoo.co.uk>.
There seems to be a few possibilities here. One is that the XML output uses
a DTD (internal or external) and you wish to output an entity reference in
the output. i.e. the output contains a DOCTYPE and an entity reference to an
entity defined in this DOCTYPE.

Another option could be that the Jelly script itself uses a DOCTYPE and an
entity reference, which is then expanded so that the output does not require
a DOCTYPE.

Finally using Jelly variables is kinda an alternative to entities - 'macros'
can be defined using Jelly variables & expressions.

I'm thinking in this case the former is probably whats required. So Martin's
suggestion of a new tag to output an entity reference...

    <xml:entity name="copy"/>

which under the covers would call

    XMLOutput.startEntity( "copy" );
    XMLOutput.endEntity( "copy" );

sounds a reasonable approach.

As Incze says, this would normally generate badly formed XML, unless the
output also contains a DOCTYPE declaration which includes the 'copy' entity.

James
-------
http://radio.weblogs.com/0112098/
----- Original Message -----
From: "Martin van den Bemt" <ml...@mvdb.net>
To: "Jakarta Commons Developers List" <co...@jakarta.apache.org>
Sent: Monday, February 03, 2003 8:49 AM
Subject: Re: [Jelly] Proposal new xml tag xml:entity


> So maybe there should be an xml:text tag to get this handled (don't use
> xslt myself though) ?
>
> Mvgr,
> Martin
>
> On Mon, 2003-02-03 at 02:02, Incze Lajos wrote:
> > On Sun, Feb 02, 2003 at 03:11:53PM +0100, Martin van den Bemt wrote:
> > > The problem is that it is not about a compliant way to do this, since
I
> > > can have any entity I define myself in my target xml (based on the
DTD).
> > > The problem is that the one that parses to the new xml file supports
> > > everything that could end up as valid xml in the target.
> > > Thats why I think there should be an addition to the current xml (or
> > > other) taglib, so we can support those outputs correctly, so we don't
> > > have to assume the xml that is doing the parsing also needs to conform
> > > to the target dtd.
> > > Hope you get my point ;)
> > >
> > > Mvgr,
> > > Martin
> > >
> >
> > If it is inevitable that you need to do that, then
> >
> > <xsl:text disable-output-escaping="yes">&copy;</xsl:text>
> >
> > should work, but don't know if it was available from jsl. (And this
works only
> > if you write a text node, not in an attribute node.)
> >
> > incze
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> >
> >
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
>

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Martin van den Bemt <ml...@mvdb.net>.
So maybe there should be an xml:text tag to get this handled (don't use
xslt myself though) ?

Mvgr,
Martin

On Mon, 2003-02-03 at 02:02, Incze Lajos wrote:
> On Sun, Feb 02, 2003 at 03:11:53PM +0100, Martin van den Bemt wrote:
> > The problem is that it is not about a compliant way to do this, since I
> > can have any entity I define myself in my target xml (based on the DTD).
> > The problem is that the one that parses to the new xml file supports
> > everything that could end up as valid xml in the target. 
> > Thats why I think there should be an addition to the current xml (or
> > other) taglib, so we can support those outputs correctly, so we don't
> > have to assume the xml that is doing the parsing also needs to conform
> > to the target dtd.
> > Hope you get my point ;)
> > 
> > Mvgr,
> > Martin
> >  
> 
> If it is inevitable that you need to do that, then
> 
> <xsl:text disable-output-escaping="yes">&copy;</xsl:text>
> 
> should work, but don't know if it was available from jsl. (And this works only
> if you write a text node, not in an attribute node.)
> 
> incze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
On Sun, Feb 02, 2003 at 03:11:53PM +0100, Martin van den Bemt wrote:
> The problem is that it is not about a compliant way to do this, since I
> can have any entity I define myself in my target xml (based on the DTD).
> The problem is that the one that parses to the new xml file supports
> everything that could end up as valid xml in the target. 
> Thats why I think there should be an addition to the current xml (or
> other) taglib, so we can support those outputs correctly, so we don't
> have to assume the xml that is doing the parsing also needs to conform
> to the target dtd.
> Hope you get my point ;)
> 
> Mvgr,
> Martin
>  

If it is inevitable that you need to do that, then

<xsl:text disable-output-escaping="yes">&copy;</xsl:text>

should work, but don't know if it was available from jsl. (And this works only
if you write a text node, not in an attribute node.)

incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Martin van den Bemt <ml...@mvdb.net>.
The problem is that it is not about a compliant way to do this, since I
can have any entity I define myself in my target xml (based on the DTD).
The problem is that the one that parses to the new xml file supports
everything that could end up as valid xml in the target. 
Thats why I think there should be an addition to the current xml (or
other) taglib, so we can support those outputs correctly, so we don't
have to assume the xml that is doing the parsing also needs to conform
to the target dtd.
Hope you get my point ;)

Mvgr,
Martin
 
On Sat, 2003-02-01 at 21:23, Incze Lajos wrote:
> > Won't work. Why not simply put &#169; (the copyright in latin-1)?
> > 
> > incze
> > 
> 
> I've checked the xsl-list for an asssertion and, yes, that's the (only)
> compliant way to go. Here is a snippet from a mail where Michael Kay
> answers to a similiar (not &copy; but &nbsp;) question:
> 
> ========================================================================
> From: Kay Michael <Mi...@icl.com>
> To: "'xsl-list@mulberrytech.com'" <xs...@mulberrytech.com>
> Subject: RE: [newbie] output &nbsp;
> Date: Thu, 20 Jul 2000 15:17:55 +0100
> 
> 
> > I have another newbie question here.
> And the #1 FAQ
> 
> > How can I output a non-blank-space or nbsp; from my xsl file...
> &#xa0;
> 
> It will come out as a non-break-space character, which means exactly the
> same to the browser software as the &nbsp; entity reference. The only
> difference is that you can't see it.
> 
> Mike Kay
> ========================================================================
> 
> The declarations of these entities can be found here:
> 
> http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent
> 
> 
> incze
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-dev-help@jakarta.apache.org
> 
> 



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
> Won't work. Why not simply put &#169; (the copyright in latin-1)?
> 
> incze
> 

I've checked the xsl-list for an asssertion and, yes, that's the (only)
compliant way to go. Here is a snippet from a mail where Michael Kay
answers to a similiar (not &copy; but &nbsp;) question:

========================================================================
From: Kay Michael <Mi...@icl.com>
To: "'xsl-list@mulberrytech.com'" <xs...@mulberrytech.com>
Subject: RE: [newbie] output &nbsp;
Date: Thu, 20 Jul 2000 15:17:55 +0100


> I have another newbie question here.
And the #1 FAQ

> How can I output a non-blank-space or nbsp; from my xsl file...
&#xa0;

It will come out as a non-break-space character, which means exactly the
same to the browser software as the &nbsp; entity reference. The only
difference is that you can't see it.

Mike Kay
========================================================================

The declarations of these entities can be found here:

http://www.w3.org/TR/xhtml1/DTD/xhtml-special.ent


incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
On Sat, Feb 01, 2003 at 08:47:36PM +0100, Incze Lajos wrote:
> > <xml:entity value="copy"/> and this will output &copy; in the document. 
> 
> You can't do that, as the output document won't be well-formed.
> 
> > I tried every other thing I could think of to get this parsed
> > (like &amp;copy; but that resolves just like it is typed, also tried
> > using CDATA for it, but &copy; resolves to &amp;copy;, etc).
> > 
> 
> What can be done is to output the tag itself and xsl can emit
> an &copy; entity on this tag iff output mode was html (not xml).
> You don't have to do anything to achieve this (jelly would output
> any tag not known for it), only add the rule to the xsl script.
> 
> Use <entity value="copy"/> in your document, and process it in
> jsl, somehow this way:
> 
> <jsl:template match="entity[@value='copy']" trim="true">
>   <!CDATA[&copy;]]>
> </jsl:template>
> 
> (Didn't check this, but hopely works.)
> 
> incze
> 

Won't work. Why not simply put &#169; (the copyright in latin-1)?

incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Re: [Jelly] Proposal new xml tag xml:entity

Posted by Incze Lajos <in...@mail.matav.hu>.
> <xml:entity value="copy"/> and this will output &copy; in the document. 

You can't do that, as the output document won't be well-formed.

> I tried every other thing I could think of to get this parsed
> (like &amp;copy; but that resolves just like it is typed, also tried
> using CDATA for it, but &copy; resolves to &amp;copy;, etc).
> 

What can be done is to output the tag itself and xsl can emit
an &copy; entity on this tag iff output mode was html (not xml).
You don't have to do anything to achieve this (jelly would output
any tag not known for it), only add the rule to the xsl script.

Use <entity value="copy"/> in your document, and process it in
jsl, somehow this way:

<jsl:template match="entity[@value='copy']" trim="true">
  <!CDATA[&copy;]]>
</jsl:template>

(Didn't check this, but hopely works.)

incze

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org