cocoon-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ilya A. Kriveshko" <i...@infoinsomniax.com>
Subject Re: newbie question: XHTML(XML)->HTML translation
Date Thu, 24 Aug 2000 14:22:06 GMT
I'm a newbie myself, so please take my answer with a certain
degree of scepticism.

Since you report getting that exception, I suspect that the XSLT
*is* being called. The problem is that the only template you have
is for <h1>, which means that all the other tags get dropped (i.e.
the text nodes get concatenated together, but the tags are gone,)
which means that text (outside of any nodes) gets output before
your only, and therefore root, element <h1>.

So, your xsl file must define a template that would match the
root node in the source xml file. For example:
  <xsl:template match="/">
    <html>
      <xsl:apply-templates/>
    </html>
  </xsl:template>

(Please, don't use this template in your case, unless just to play
around, as it will drop most of your tags . Read further.)

Since the structure of your output HTML document is already
defined very closely by the source XHTML file, you need a
sort of a catch-all template that would preserve the tags and
attributes defined in your source XHTML. Here is an example
(this one you can use, and it will work in your case):

  <xsl:template match="*|/" priority="-1.0">
    <xsl:variable name="elem-name" select="name()"/>
    <xsl:element name="{$elem-name}">
      <xsl:for-each select="attribute::*">
        <xsl:attribute name="{name()}">
            <xsl:value-of select="."/>
        </xsl:attribute>
      </xsl:for-each>
      <xsl:apply-templates/>
    </xsl:element>
  </xsl:template>

This template matches any source element node, including the root,
and outputs it with all of the source element's attributes. Basically,
it copies the structure and contents of your XHTML document intact.
I set the priority of this template to "-1.0" so that it only gets invoked
if no other matching templates with implicit proiorities (0, -0.25,
-0.5) exist - see http://www.w3.org/TR/xslt#conflict for details.
So, your match="h1" template will take precedence and will get
applied properly.

Any critique of the statements I made is welcome: I will be
following this thread. :-)
---
Ilya


Kim Bisgaard wrote:

> Hi,
>
> I am trying to have Cocoon-1.7.4 do the default XHTML to HTML translation, but
> at the same time try to intercept/precede it to do layout customization. But my
> XSLT instructions does not get called.
>
> This is my test page:
> <?xml version="1.0" encoding="iso-8859-1"?>
> <?xml-stylesheet href="dmi.html.xsl" type="text/xsl"?>
> <?cocoon-process type="xslt"?>
> <html xmlns="http://www.w3.org/1999/xhtml">
> <head>
> <meta name="generator" content="HTML Tidy, see www.w3.org" />
> <title>XHTML test page</title>
> </head>
> <body>
> <h1>XHTML test page</h1>
>
> <blockquote><i>Some filling should be in here</i></blockquote>
> </body>
> </html>
>
> and here is my XSLT instructions:
> <?xml version="1.0"?>
> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
> <xsl:output method="html"/>
>   <xsl:template match="h1">
>            <h1><center>
>                <xsl:apply-templates/>
>            </center></h1>
>   </xsl:template>
> </xsl:stylesheet>
>
> Can anybody please give me a hint to what I am doing wrong here?
>
> I sometimes gets the following errors but I cannot desipher them. Any help in
> that?
>         org.apache.xalan.xslt.XSLProcessorException: Warning: can't output text
> before document element!  Ignoring..
>         org.xml.sax.SAXException: Warning: can't output text before document
> element!  Ignoring...
>
> Thanks in advance,
>
> --
> Kim Bisgaard
>
> Oersted Science Data Center
> Solar-Terrestrial Physics Division           Phone: +45 3915 7495 (direct)
> Danish Meteorological Institute              Fax: +45 3915 7460 (division)
> http://www.dmi.dk/solar-terrestrial/ -- Division homepage
> http://www.dmi.dk/projects/oersted/  -- Oersted Satellite
> http://www.dmi.dk/projects/wdcc1/    -- WDC C1 for geo-magnetism
>   These are our official Web addresses - ignore any change in the server name
>   which may occur while browsing this site. Unfortunately, these pages are
>   not reachable via links from the main institute pages - http://www.dmi.dk
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: cocoon-users-help@xml.apache.org


Mime
View raw message