Hi Peter,

Here's one way to respect processing instructions in Cocoon2:

Create a pipeline which reads an xml doc, finds the PI element and returns
the contents of the xsl document which it specifies. I've called this
"get-stylesheet.xsl", since it returns the stylesheet for a document. It
will return different stylesheets depending on the source document.

Create a separate pipeline which reads an xml doc and transforms it using
the stylesheet returned by the first pipeline.

I've done a little example, which I enclose. It is pretty basic - it assumes
all stylesheets are in the same folder, assumes they all produce html, and
it handles only 1 PI per source document, which it assumes refers to an XSL
stylesheet, but it's simple and you can easily modify it to suit a more
complicated setup if necessary.

The source documents (example/documents/*.xml) are assumed to contain a PI
like the one below:

<?xml-stylesheet href="hello.xsl" type="text/xsl"?>

The hello.xsl file is assumed to be in the example/stylesheets folder.

The sitemap snippet defines the 2 pipelines:

<map:match pattern="get-stylesheet-for/*.xml">
  <map:generate src="example/documents/{1}.xml"/>
  <map:transform src="example/stylesheets/get-stylesheet.xsl"/>
  <map:serialize type="xml"/>
</map:match>

<map:match pattern="test/*.html">
  <map:generate src="example/documents/{1}.xml"/>
  <map:transform src="cocoon://get-stylesheet-for/{1}.xml"/>
  <map:serialize type="html"/>
</map:match>


The stylesheet "get-stylesheet.xsl":
---------------------------------------------------------
<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

  <!-- copy contents of the PI's href -->
  <xsl:template match="processing-instruction()">
    <xsl:variable name="stylesheet"
      select="substring-before(substring-after(.,'href=&quot;'),'&quot;')"
    />
    <xsl:apply-templates mode="copy" select="document($stylesheet)"/>
  </xsl:template>

  <!-- ignore the rest of the document -->
  <xsl:template match="@*|*"/>

  <!-- for copying the stylesheet referred to by the PI -->
  <xsl:template match="@*|node()" mode="copy">
    <xsl:copy>
      <xsl:apply-templates select="@*|node()" mode="copy"/>
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>
---------------------------------------------------------

The

> -----Original Message-----
> From: Peter Flynn [mailto:[EMAIL PROTECTED]]
> Sent: Monday, 29 April 2002 01:45
> To: [EMAIL PROTECTED]
> Subject: Re: Serving static XML files a la Cocoon-1
>
>
> > Key distinction:
> >
> > DTDs are used to *VALIDATE*, not render.
>
> That's one reason. The other is to allow the document to be edited in
> a structured editor. Our documents are all created by humans, so we
> need to use a system which guides creation and editing. The Document
> Type Declaration is therefore present in the XML file so that the
> type of document can be detected by software (whether or not the DTD
> is used). The root element type name is insufficient for this (too
> many DTDs for articles use the root element type <article> already :-)
>
> > True, but it is not uncomon to have a working stylsheet in
> > applications, and before release the web monkeys are let loose to
> > make it look nice.  Of course both these developments can be
> > happening simultaneously.  THe doc writer should not care how the
> > info is presented, that isn't their concern.
>
> This is a contentious point. Frequently the doc writer is the only one
> who knows how the information should be presented: document stylists
> are notoriously ignorant of technical matters, just as authors are
> notoriously ignorant of typographic matters.
>
> > >>The sample sitemap bundled with Cocoon offers these
> 'defaults' already.
> > >
> > > If that is so, why does it not transform my sample XML
> document with
> > > its accompanying XSL stylesheet?
> >
> > Are you volunteering to write something that reacts to PIs?
>
> :-) Done too many of them already.
>
> > It's not really a trivial task, and considering the amount of work
> > involved in it, for something we really don't want to encourage,
> > its not a likely thing to happen soon.
>
> No, I don't want to if I can avoid it. PIs should be kept for their
> real task: affecting processing *outside* the domain of the processor
> (think TeX/dvi \specials). Basically tweaks.
>
> > Going back to your "associated" XSL document, and
> distributing the files
> > w/o a server: you can still do that with your PIs.  A
> browser that knows
> > how to treat the PIs will do so correctly.  However, for
> serving up to
> > older browsers, you should use the preferred method.  Your
> Sitemap won't
> > change much.  You stated something like every few years.  When you
> > change your site, you only need to update the sitemap to
> point to the
> > new stylesheet--even if you have hundreds of documents by then.
>
> I still need to bind a stylesheet to the documents. The Document Type
> is the obvious key, but I can't see how to achieve this in
> sitemap.xmap
>
> ///Peter
>
> ---------------------------------------------------------------------
> Please check that your question has not already been answered in the
> FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>
>
> To unsubscribe, e-mail: <[EMAIL PROTECTED]>
> For additional commands, e-mail: <[EMAIL PROTECTED]>
>
>


---------------------------------------------------------------------
Please check that your question has not already been answered in the
FAQ before posting. <http://xml.apache.org/cocoon/faqs.html>

To unsubscribe, e-mail: <[EMAIL PROTECTED]>
For additional commands, e-mail: <[EMAIL PROTECTED]>

Reply via email to