Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Problems trying to XSL transform a document with entities.

Reply
Thread Tools

Problems trying to XSL transform a document with entities.

 
 
annoyed tuna
Guest
Posts: n/a
 
      04-20-2005
I was wondering if someone could help me out. I'm trying to perform an
XSL transformation on an XML document that uses entities. While I can
do XSLT on a file without entities, it all falls apart when I try and
add an entity. Here are my files...

-----TEST.XML------

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!DOCTYPE document [
<!ENTITY externalparagraph SYSTEM "test2.xml">
]>
<document>
<paragraph>Lorem ipsum dolor.</paragraph>
<paragraph>Duis iaculis purus id augue.</paragraph>
&externalparagraph;
</document>

-------------------

-----TEST2.XML-----
<?xml version="1.0" encoding="UTF-8"?>
<paragraph>hello world!</paragraph>
-------------------


-----TEST.XSL------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlnssl="http://www.w3.org/1999/XSL/Transform">
<xslutput method="html" encoding="utf-8"
doctype-system="http://www.w3.org/TR/html4/loose.dtd"
doctype-public="-//W3C//DTD HTML 4.01 Transitional//EN" />
<xsl:template match="/">
<xsl:for-each select="//paragraph">
<xsl:value-of select="."/>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
-------------------

Now, this works fine when I load up text.xml in IE6, however if I load
it up in Firefox 1.0 it fails.

It also fails when I try and do my transformation usine
MSXML2.DOMDocument in ASP.

Can anyone give me some pointers as to what I'm doing wrong?
 
Reply With Quote
 
 
 
 
David Carlisle
Guest
Posts: n/a
 
      04-20-2005

The XML spec allows non-validating parsers to _not_ read external parts
of a DTD (for various reasons to do with history, security and
politics

mozilla family browsers take up this option and don't ever read DTD
parts from another site. If the filename or public ID matches a DTD in
the $MOZILLAHOME/res cached dtd areas (which means, essentially XHTML or
XHTML+MathML then it reads the version it has locally, but it never
reads the external DTD file.

If XSLT sees an unexpanded entity in its input, it dies.

> Can anyone give me some pointers as to what I'm doing wrong?


Nothing is wrong (except your expectations).

In the case of ASP I'm sure you can make it work, as MSXML does normally
read dtd files, it's probably a security issue (I don't know) In the case
of firefox, you are doomed.

David
 
Reply With Quote
 
 
 
 
annoyedtuna@yahoo.co.uk
Guest
Posts: n/a
 
      04-20-2005
Fortunately, browser compatibility is not a requirement as I intend to
do my XSL processing server-side. However I still can't get it working
with MSXML and ASP. The doctype gets output, but that's all. Does
anyone have any sample code that I might be able to copy.

Also, is there a better way of achieving my goal? I think perhaps XLink
may be an option.

I just want to be able to import an xml document in top another and do
an XSL transformation as if it were all one file.

For example I might have lots of XML files that need a list of
countries and their respective database codes. However I want to be
able to update those countries from time to time and only change one
XML file.

Can anyone give me any pointers on how to do this if entities are not
the way to go?

 
Reply With Quote
 
David Carlisle
Guest
Posts: n/a
 
      04-20-2005

As I said msxml normally follows external dtd references so I'm
surprised it doesn't work from your asp page. Hard to tell really sounds
like a permissions problem I would guess (but ASP ain't my thing really
so I'm only guessing

Otherwise it's easy enough to use xlink or xinclude or even easier roll your own:


If your main document says

<document>
<paragraph>Lorem ipsum dolor.</paragraph>
<paragraph>Duis iaculis purus id augue.</paragraph>
<foo href="other-doc.xml"/>
</document>


and your styleshet has

<xsl:template match="foo">
<xsl:apply-templates select="document(@href)"/>
</xsl:template>

then processing will move to other-doc.xml when you hit the foo element.

David
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
XSL transform trying to be smarter? Wizfrog XML 6 07-24-2007 12:02 PM
XSL Question tp xsl:for-each and xsl:variable schaf@2wire.ch XML 1 05-27-2005 09:25 PM
blocking I/O with javax.xml.parsers.DocumentBuilder.parse() and javax.xml.transform.Transformer.transform() jazzdman@gmail.com Java 1 03-27-2005 06:56 AM
Displaying XML document in ASP.NET page using XSL Transform Barry Anderberg XML 1 04-08-2004 04:06 AM
Displaying XML document in ASP.NET page using XSL Transform Barry Anderberg ASP .Net 2 04-08-2004 04:06 AM



Advertisments