Making XSLT stylesheets more modular

P

Paulo Pinto

Hi,

I have already several XSLT stylesheets that
make use of <xslt:include> "command". Now
I wanted to make them a bit more modular but
I'm stuck.

I want to take out the generated HTML code
for the footer and header to some files that could
be included by the stylesheets.

So far I wasn't able to use any XSLT inclusion mechanism
that works.

Any ideas?

Thanks in advance,
Paulo Pinto
 
D

David Carlisle

Paulo Pinto said:
Hi,

I have already several XSLT stylesheets that
make use of <xslt:include> "command". Now
I wanted to make them a bit more modular but
I'm stuck.

I want to take out the generated HTML code
for the footer and header to some files that could
be included by the stylesheets.

So far I wasn't able to use any XSLT inclusion mechanism
that works.

Any ideas?

Thanks in advance,
Paulo Pinto

what did you try?

sounds like you want to make a stylesheet that just has a named template
that generates a header then xsl:include that into your main stylestss
and use call-template at teh point that you want the header to apear.

David
 
S

SirMike

Paulo said:
I want to take out the generated HTML code
for the footer and header to some files that could
be included by the stylesheets.
Try to wrap the html into simple xsl and then include.
 
T

Tjerk Wolterink

Paulo said:
Hi,

I have already several XSLT stylesheets that
make use of <xslt:include> "command". Now
I wanted to make them a bit more modular but
I'm stuck.

I want to take out the generated HTML code
for the footer and header to some files that could
be included by the stylesheets.

So far I wasn't able to use any XSLT inclusion mechanism
that works.

Any ideas?

Thanks in advance,
Paulo Pinto

i think i know what you mean,
you cannot have the footer and header html in seperate files because the xml must remain a tree

<xsl:template name="layout">
<a>
<b>
<xsl:call-template name="body"/>
</b>
</a>
</xsl:template>

cannot be separated in:

<xsl:template name="layout">
<xsl:call-template name="header"/>>
<xsl:call-template name="body"/>
<xsl:call-template name="footer"/>
</xsl:template>

<xsl:template name="header">
<a>
<b>
</xsl:template>

<xsl:template name="footer">
</b>
</a>
</xsl:template>
 
P

Paulo Pinto

Thanks for the info.

I will try to play around today at home
and probably come up with a more concret
example.
 
A

Andy Dingley

i think i know what you mean,

This explanation sounds likely.
you cannot have the footer and header html in seperate files because the xml must remain a tree

You can still have the "header" and "footer" generated by named
templates, you just need to avoid the <html> <head> and <body>
elements. This isn't a big restriction, because they're generally
pretty static and can just be inserted into the top level template.
 
T

Tjerk Wolterink

Andy said:
This explanation sounds likely.

i think you mean unlikely?!?!?!
You can still have the "header" and "footer" generated by named
templates, you just need to avoid the <html> <head> and <body>
elements. This isn't a big restriction, because they're generally
pretty static and can just be inserted into the top level template.


it can be done, but often the conten of the page is between a tag. That tag is openend in the header
and closed in the footer. So .. yes it is possible, but it is restrictive
 
A

Andy Dingley

it can be done, but often the conten of the page is between a tag. That tag is openend in the header
and closed in the footer.

If there's a single element spanning that far, then that's not a
footer, it's the body of the page.

Many of my pages have a structure like this :

<html>
[...]
<body>

<div class="header" >
[...]
</div>

<div class="nav-stuff" >
[...]
</div>

<div class="body-text" >
<div class="stuff" >
[...]
</div>

<div class="other-stuff" >
[...]
</div>
</div>

<div class="footer" >
[...]
</div>

</body></html>



Now generating the element <div class="footer" > is a valid thing for
an XSLT templte to be doing, but trying this:

<xslt:template name="output-footer" >
</div>
<div class="footer" >
[...]
</div>
</xslt:template>

is not only poorly-formed, but it's semantically inappropriate too.
Close that body text from the same scope in which you opened it,
whether you're writing XSLT or any other page-generation language.
 
P

Paulo Pinto

OK, here goes a more detailed example.

I already have the following working situation
in my web site.

news.xml -> news.xsl -> news.html
| loads
v
toc.xml and toc.xsl


So toc.xsl is loaded with <xsl:include> and latter
on in the news.xsl file I do a

<xsl:apply-templates select="document('../toc.xml')/toc"/>

in the place where I want the menu to appear.

toc.xml is a xml file with the description of the web site
navigation menus.

All top level xsl files for the site follow this scheme.
Meaning that they all load toc.(xml,xsl) in order to
avoid having code related with the site navigation.

Now I would like to make those files evern lighter by
making a similar use case for the generation of the header
and footer of each page.

But now I just have the XHTML code that I want to insert
into a given place.

Hope that this explains better what I'm trying to achive.
 

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,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top