setting DOCTYPE and also including a file in the output

D

danmc91

Hello,

I'm new to xml and xslt but that should be obvious from my question.

I'm trying to help my wife set up some web pages with some of her art
work and what I'm trying to do is find a way to get all of the
information about the pictures in an XML file and then use xslt to
produce some different html files.

My first problem is I can't seem to figure out how to get this to
appear at the top of my output file:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

The next problem I'm having is how to include an extra file in the
output. I had some very old scripts which could parse html files with
server side includes and produce static html files that didn't need a
server with SSI enabled. I'd been using this mechanism to include a
standard footer and some navigation links on all web pages. Since I'm
looking to migrate towards xml and xslt I'm trying to find a way to
still include the contents of a file in the output.

The .dtd file .xsl file, and input .xml file's I have so far are at:

http://home.comcast.net/~dmcmahill/tmp/gallery.dtd
http://home.comcast.net/~dmcmahill/tmp/gallery.xsl
http://home.comcast.net/~dmcmahill/tmp/drawings1.xml

xsltproc gallery.xsl drawings1.xml > drawings1.shtml

seems to give the right thing except for the DOCTYPE bit and I still
need to run my homebrewed SSI processor to convert the .shtml file to
..html.

Any suggestions? Am I going about this completely the wrong way? For
how much programming in all sorts of languages, I'm finding xslt rather
confusing...

-Dan
 
M

Martin Honnen

danmc91 said:
The next problem I'm having is how to include an extra file in the
output. I had some very old scripts which could parse html files with
server side includes and produce static html files that didn't need a
server with SSI enabled. I'd been using this mechanism to include a
standard footer and some navigation links on all web pages.

The XSLT language has an xsl:include instruction to include stylesheet
modules. Then there is the document function to load secondary XML
documents to be processed besides the main XML input.

That means you have two choices, if the footer is a snippet of
well-formed X(HT)ML (e.g.
<div xmlns="http://www.w3.org/1999/xhtml">
<p>....</p>
</div>
) then you can pull it in with the document function and simply copy it
to the result tree e.g.
<xsl:copy-of select="document('footer.xml')/*"/>
Note the namespace declaration above in the snippet, if your aim is to
output XHTML then the separate file needs to have the XHTML namespace
declaration present if you simply want to copy the elements.

Alternatively you could write a stylesheet module with a named template
making up the footer e.g.
<xsl:template name="make-footer" xmlns="http://www.w3.org/1999/xhtml">
<div>
<p>...</p>
</div>
</xsl:template>
then include that stylesheet with xsl:include and call e.g.
<xsl:call-template name="make-footer"/>
where you want to include the footer.

These are the tools XSLT 1.0 offers, additionally you might want to look
into XInclude to compose XML from different sources independent of XSLT.
 
D

danmc91

Thanks Martin! Both of your suggestions worked and did exactly what I
was trying to do.

-Dan
 

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

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top