Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 12th, 2011, 03:05 PM
Registered User
 
Join Date: Oct 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default XML DTD and XSLT issue

I am new to xslt so please excuse my naive question.
I have an xml file with DTD, when I try to convert this xml file to html using xslt, I get errors. When i remove the DTD and repeat the process i get no errors. Please advice me on this issue.

XML with DTD:

<!DOCTYPE art public "-//ES//DTD full length article DTD version 4.3.1//EN"[]><ART VERSION="4.3.1" JID="AOS" AID="392" DOCSUBTY="FLA" PII="S0361368202000302" DOI="10.1016/S0361-3682(02)00030-2"><COPYRIGHT TYPE="full-transfer" YR="2003">Elsevier Ltd</COPYRIGHT><FM><ATL>The colour of accountancy: examining the salience of race in a professionalisation project</ATL></FM></ART>

XML without DTD:

<ART VERSION="4.3.1" JID="AOS" AID="392" DOCSUBTY="FLA" PII="S0361368202000302" DOI="10.1016/S0361-3682(02)00030-2"><COPYRIGHT TYPE="full-transfer" YR="2003">Elsevier Ltd</COPYRIGHT><FM><ATL>The colour of accountancy: examining the salience of race in a professionalisation project</ATL></FM></ART>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40" >
<xsl:output method="html" encoding="UTF8" />
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<html>
<head><title>Hello</title></head>
<body><b>Title:</b>
<xsl:value-of select="/ART/FM/ATL"/>
</body></html>
</xsl:template>
</xsl:stylesheet>

Thanks,
Neha
 
Old October 13th, 2011, 05:31 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Well I don't know much about Doctype declarations, but I suspect you get errors because the DTD isn't valid.

Saxon gives me the following error: "The document type declaration for root element type "art" must end with '>'"

So basically your XML document isn't valid. Fix that and you should be fine.
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
 
Old October 13th, 2011, 07:52 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

Can you tell us which error exactly you get?
One problem I see is that XML is case-sensitive so if you have "DOCTYPE art" then the root element's name needs to be "art" and not "ART" as you have it in your sample.
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 13th, 2011, 08:20 AM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Thumbs up

If you have rights to edit the XML then change
Code:
<!DOCTYPE art public "-//ES//DTD full length article DTD version 4.3.1//EN"[]>
to
Code:
<!DOCTYPE ART PUBLIC "-//ES//DTD full length article DTD version 4.3.1//EN" "dummy.dtd" []>
Just create a dummy.dtd file in the path of XML. You wont face any error.
__________________
Rummy
 
Old October 13th, 2011, 09:28 AM
Registered User
 
Join Date: Oct 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

@samjudson, mrame, Martin Honnen...I do get the same exact error message.
This is from an XML file that comes from a publisher and I cannot change the xml file or the DTD. I did try to change art to ART, it did not work.

Is there any other way to solve this issue.

Thanks again for the help.!!!
Neha

Last edited by nehap8; October 13th, 2011 at 09:31 AM..
 
Old October 13th, 2011, 09:48 AM
Registered User
 
Join Date: Oct 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Another similar example, here i don't get any error, but no output is displayed when the xml has DTD. But when the DTD is removed i get the "jid" tag element value.

XML with DTD:

<?xml version="1.0" encoding="utf-8"?><!DOCTYPE simple-article PUBLIC "-//ES//DTD journal article DTD version 5.1.0//EN//XML" "http://schema.elsevier.com/dtds/document/fulltext/warehouse/art510/art510.dtd"><simple-article version="5.1" docsubtype="abs"><item-info><jid>YDBIO</jid></item-info></simple-article>

XML without DTD:

<?xml version="1.0" encoding="utf-8"?><simple-article version="5.1" docsubtype="abs"><item-info><jid>YDBIO</jid></item-info></simple-article>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40" >
<xsl:output method="html" encoding="UTF8" />
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<html>
<head><title>Hello</title></head>
<body><b>JID:</b>
<xsl:value-of select="/simple-article/item-info/jid"/>
</body></html>
</xsl:template>
</xsl:stylesheet>

Thanks,
Neha
 
Old October 13th, 2011, 10:58 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The DTD has this line in it:

xmlns CDATA #FIXED %ESJA.xmlns;

This means that when the XML parser processes the file using the DTD, an xmlns="...." attribute is added to the outermost element. This has the effect of putting all unprefixed element names in a namespace, which means you have to change your XSLT code so that it matches names in that namespace.

People who design DTDs like this think they are being really smart by saving the XML author the trouble of adding a namespace declaration. I'm sure if their bosses realised the trouble that they cause to consumers of the document by hiding the fact that it's in a namespace, they would be sacked and lose their pension rights.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old October 13th, 2011, 11:14 AM
Registered User
 
Join Date: Oct 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a lot for your explanation. I am very new to XML and XSLT, please could you let me know where to look for the namespace information to reference the tags correctly.

Please excuse me if the question is naive.

PS: in one of the publisher xslt for I found, the simple-article tag is referenced as es:article. I am not sure from where to get this information.


Also with my first example, would you know why I am getting that error.


Thanks,
Neha

Last edited by nehap8; October 13th, 2011 at 11:17 AM..
 
Old October 13th, 2011, 11:27 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

The namespace name is declared as an entity in the DTD, it is http://www.elsevier.com/xml/ja/dtd so you need to change your stylesheet code to
Code:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"  xmlns:df="http://www.elsevier.com/xml/ja/dtd" exclude-result-prefixes="df" version="1.0">
<xsl:output method="html" encoding="UTF8" />
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<html>
<head><title>Hello</title></head>
<body><b>JID:</b>
<xsl:value-of select="/df:simple-article/df:item-info/df:jid"/>
</body></html>
</xsl:template>
</xsl:stylesheet>
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 13th, 2011, 11:33 AM
Registered User
 
Join Date: Oct 2011
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks a ton that works..!!

Any comments on what i could do to fix the first example would be greatly appreciated.

XML with DTD:

<!DOCTYPE art public "-//ES//DTD full length article DTD version 4.3.1//EN"[]><ART VERSION="4.3.1" JID="AOS" AID="392" DOCSUBTY="FLA" PII="S0361368202000302" DOI="10.1016/S0361-3682(02)00030-2"><COPYRIGHT TYPE="full-transfer" YR="2003">Elsevier Ltd</COPYRIGHT><FM><ATL>The colour of accountancy: examining the salience of race in a professionalisation project</ATL></FM></ART>

XML without DTD:

<ART VERSION="4.3.1" JID="AOS" AID="392" DOCSUBTY="FLA" PII="S0361368202000302" DOI="10.1016/S0361-3682(02)00030-2"><COPYRIGHT TYPE="full-transfer" YR="2003">Elsevier Ltd</COPYRIGHT><FM><ATL>The colour of accountancy: examining the salience of race in a professionalisation project</ATL></FM></ART>

XSL:

<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/TR/REC-html40" >
<xsl:output method="html" encoding="UTF8" />
<xsl:strip-space elements="*"/>

<xsl:template match="/">
<html>
<head><title>Hello</title></head>
<body><b>Title:</b>
<xsl:value-of select="/ART/FM/ATL"/>
</body></html>
</xsl:template>
</xsl:stylesheet>

PS: I found this DTD on web http://www.info.sciverse.com/UserFil...d43/art431.dtd

Please let me know if can provide with more information to help identify the problem.


Thanks,
Neha

Last edited by nehap8; October 13th, 2011 at 11:39 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Filter XML file with an XSLT using DTD menhir666 XSLT 1 February 3rd, 2009 11:50 AM
Automated tool to convert XML from DTD to DTD lsantos2000 XSLT 2 October 17th, 2007 08:21 AM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
Issue with DTD tgopal CSS Cascading Style Sheets 2 September 20th, 2006 04:15 AM
DTD base XSLT Grouping ROCXY XSLT 1 February 27th, 2006 07:21 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.