Problems trying to XSL transform a document with entities.

A

annoyed tuna

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"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput 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?
 
D

David Carlisle

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
 
A

annoyedtuna

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?
 
D

David Carlisle

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top