have a stylesheet generate another stylesheet based on XML?

S

Steven An

I'm gonna describe the situation I'm dealing with..but if you're not
interested, just skip to the last line where I bluntly ask my question
:)

Here's my scenario: I've got a huge website that has many pages.
Each page has its own content (which changes often). So I wanna use
XSLT stylesheets to create these pages (so I can modify the appearance
of the whole site easily). So that's pretty straightforward: one XML
file per page, with a common stylesheet for them all.

However, each page also has a navigation menu. This menu should look
the same for all pages. You may think..just put the navigation menu
in the page stylesheet! But..what if I want to use XSLT to create
this menu as well? Because say I have a LOT of items in this menu and
they all need to have a common style (that I want to be easily
modifiable).

One solution is that I could put the menu data in with each page XML,
and thus have the page stylesheet create the menus and the page..but
this seems wasteful for many reasons. So here's the solution I'd like
to use: I have a stylsheet which takes in the menu XML and then
outputs ANOTHER stylesheet that transforms my page data. So the
latter stylesheet would have all the generated menu HTML in it
already.

The question: How do I have a stylesheet output a stylesheet (based on
XML input)? I've tried using CDATA, but that's really messy and
doesn't quite work (I get a lot of & gt;'s and what not). Or is there
a better way to deal with my situation (which I'm sure is not
uncommon)?

Any advice would be appreciated,
Steve
 
M

Martin Honnen

Steven An wrote:

The question: How do I have a stylesheet output a stylesheet (based on
XML input)? I've tried using CDATA, but that's really messy and
doesn't quite work (I get a lot of & gt;'s and what not). Or is there
a better way to deal with my situation (which I'm sure is not
uncommon)?

Use a namespace alias e.g.
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xso="http://www.w3.org/1999/XSL/Transform/Output"
version="1.0">

<xsl:namespace-alias stylesheet-prefix="xso"
result-prefix="xsl" />

<xsl:template match="/">
<xso:stylesheet ...>
...
<xso:stylesheet>
</xsl:template>
 

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,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top