RE: [xsl] retaining entity declarations while converting from one xml format to another

Subject: RE: [xsl] retaining entity declarations while converting from one xml format to another
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Wed, 16 Dec 2009 09:44:47 -0000
> Please look at the saxon extension function saxon:doctype.
>
> http://saxon.sourceforge.net/saxon6.5.5/extensions.html#saxon:doctype
>
> which provides the mechanism to create the entities. In your
> case you have to re-generate the entities in XML file.

I suspect that he wants entity references to be copied, rather than entity
declarations. The saxon:doctype extension allows you to construct a DTD
(internal subset) containing entity declarations, and you can construct
references to those entities using character maps or
disable-output-escaping. But to get access to entity declarations and entity
references in the source XML, you need to stop the XML parser expanding
them, which you can do using Andrew Welch's LexEv.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay


>
> Regards,
> Ganesh
>
>
> On Wed, Dec 16, 2009 at 6:23 AM, David Carlisle
> <davidc@xxxxxxxxx> wrote:
> >
> >> I am sorry I forgot to mention one piece of information
> here. These
> >> input files were originally SGML and were then converted to well
> >
> > but assuming spoon.jpg is a jpeg file, the same would apply
> in SGML as
> > well, image entities should be NDATA (not parsed) and referenced as
> > attribute values, not using &  ; notation.
> >
> >> So when I do the <xsl:copy> the entities are not copied over.
> >
> > parsed entities (referenced by &) are expanded by the XML parser
> > before XSLT even sees the input. So XSLT can not copy them
> as it never
> > sees them.
> >
> > But you can not reference a jpg file that way.
> >
> > An NDATA entity is referenced as attribute value typically
> something
> > like
> >
> > <!ENTITY spoon.jpg SYSTEM "spoon.jpg" NDATA jpg>
> >
> > ...
> >  <image ref="spoon.jpg"/>
> > ...
> >
> > if you access the entity this way, then the attribute value is
> > available to xslt and you can look up the SYSTEM URI using
> unparsed-entity-uri().
> >
> >
> > But you showed a parsed entity declaration
> >
> >
> >
> > <!ENTITY spoon.jpg SYSTEM "spoon.jpg" >
> >
> > which would be acceessed by
> >
> > & s p o o n . j p g ;
> >
> > such a reference would be expanded by the xml parser before
> xslt sees
> > the data (and generate a fatal error if it is a jpeg file
> rather than
> > xml)
> >
> > As you haven't shown how you are referencing the entities in the
> > source file I can't really guess what to suggest.
> >
> > david
> >
> >
> ______________________________________________________________________
> > __ The Numerical Algorithms Group Ltd is a company registered in
> > England and Wales with company number 1249803. The
> registered office
> > is:
> > Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.
> >
> > This e-mail has been scanned for all viruses by Star. The
> service is
> > powered by MessageLabs.
> >
> ______________________________________________________________________
> > __

Current Thread