I’m exploring the XML -> XSLT -> HTML meme for producing web content. I have very little XSLT experience.
I’m curious what mechanisms are available in XSLT to handle abstractions or ‘refactoring’.
For example, with generic HTML and a service side include, many pages can be templated and decomposed to where there are, say, common header, nav, and footer segments, and the page itself is basically the body.
The common markup languages, JSP, PHP, ASP, go as far as to allow all of those segments to have dynamic content (such as adding the user name to every header block).
JSP goes even farther by allowing you to create Tag files, which can accept arguments to be used when generating the content, and even surround and work on content within the tags themselves.
I’m curious similar functionality is done within XSLT. What facilities are there to make reusable block of XSLT for things like creating HTML pages?
For my own project, this is how I divided up my pages. There was a template.xsl file which was imported by each of my XSLs. Most pages just had template.xsl, but some pages such as cart, etc. needed their own because of the different kind of data they were parsing.
This is a snippet from my template.xsl. I threw in all the common stuff in here, and then gave the opportunity for my pages to add their own information through
call-template.An example of how my css tag would respond. Note that it calls
css-extended.css only had the the common css’ that would apply across all pages. Some pages needed more. Those could override css-extended. Note that is needed becausecall-templatewill fail if a page calls a template but doesn’t define it anywhere.My container would work in a similar manner– common stuff was defined and then each page could just provide an implementation. A default implementation was in the XSL. (in
content)It worked quite beautifully for me. If there are any questions I can answer for you, let me know.