Re: [xsl] XSLT 2.0 question

Subject: Re: [xsl] XSLT 2.0 question
From: Robert Koberg <rob@xxxxxxxxxx>
Date: Mon, 18 Mar 2002 03:05:42 -0800
hi,

You seem to be defeating the purpose of separating your content from your presentation (that is why we like XSLT, right?). This app sounds like it needs to be redesigned... If your app cannot take more than one *primary* XSLT, I would say it is pretty limited. But, I may be misunderstanding what you wrote...

-Rob


Bryan Rasmussen wrote:


thanks, I'd never thought about this  way to use embedded stylesheets(they
always seemed sort of useless to me) but unfortunately this isn't quite what
I want to do.
See we're working on an application in which there will be a lot of
pre-written stylesheets to do transformations into various formats, the xml
will come from Word, the end-user isn't going to know what the stylesheets
are called as our target audience is not very technical besides some may be
internal program resources, however as we expect that some of them will know
html and some simple programming we are allowing different ways to
include/write code into the Word documents, one of these code types could be
xslt.
For many reasons too voluminous to go into here I can't change the structure
of how stylesheets are run in this app, that is to say the main stylesheet
needs to be the external one, I don't see anyway this could be done from
xslt 1.0, although I could prob. construct a hack whereby the app reads in
the xslt, reads xml document, creates a node <xsl:import name=" <<put the
name of the xml document here>>"/> and then have to do some parameter
checking to tell me to switch between apply-imports and apply-templates at
points in the document. sounds awful, is awful, that's why it's called a
hack :) also introduces the dreaded side effects, not to mention being
potentially the slowest thing ever. Don't want to do anything with side
effects, thought there might be some way to achieve it in xslt 2.0 without
side effects.

am wondering if it would be possible to set up solutions that do the
following in xslt 2.0, let us say you run your xslt against an xml
document that contains inline xslt code, perhaps just a single
xsl:template, would there be any way, hopefully incredibly involved
and complex :) to declare that inline templates should be run and
take precedence over templates in the xslt.


Yep, they're called embedded stylesheets. See
http://www.w3.org/TR/xslt#section-Embedding-Stylesheets in XSLT 1.0 or
http://www.w3.org/TR/xslt20/#embedded in the XSLT 2.0 WD.


Say that your stylesheet was called 'stylesheet.xsl', you could do:


<doc>
<person>...</person>


<xsl:stylesheet version="1.0" id="stylesheet"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:import href="stylesheet.xsl" />


  <xsl:template match="person">
    do something
  </xsl:template>


</xsl:stylesheet>
</doc>


If you use the embedded stylesheet (accessing it by its ID), then it
imports your main stylesheet (stylesheet.xsl) and overrides its
content in just the same way as importing a stylesheet does normally.
So your local style information for the person element has priority.


To make this work, you have to declare the id attribute on
xsl:stylesheet as an ID attribute, so the top of the document will
probably actually look like:


<?xml version="1.0"?>
<!DOCTYPE doc [
<!ELEMENT xsl:stylesheet ANY>
<!ATTLIST xsl:stylesheet id ID #REQUIRED>
]>
<?xml-stylesheet type="text/xsl" href="#stylesheet"?>
<doc>
<person>...</person>


<xsl:stylesheet version="1.0" id="stylesheet"


xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>


<xsl:import href="stylesheet.xsl" />


  <xsl:template match="person">
    do something
  </xsl:template>


</xsl:stylesheet>
</doc>


Cheers,


Jeni

---
Jeni Tennison
http://www.jenitennison.com/


XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list




XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list



Current Thread