Re: No output? What's wrong?

Discussion in 'XML' started by Dimitre Novatchev, Jul 29, 2003.

  1. There's no "head" element in your source.xml -- this is why the
    xsl:apply-templates in your code does not select anything to be matched
    against your templates and, therefore, no processing is being performed.



    =====
    Cheers,

    Dimitre Novatchev.
    http://fxsl.sourceforge.net/ -- the home of FXSL



    "chris" <> wrote in message
    news:koiVa.2872$...
    > Hi,
    >
    > I'm trying to transform html into html but somethings wrong. I get the
    > following output on a validated xhtml file (the head and body are
    > non-empty). I want to output the head, then perform a transformation on
    > the body (to add a css menu) but I can't even get the contents of the
    > head...
    >
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    >
    > <!DOCTYPE html
    > PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    > <html/>
    >
    >
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <xsl:transform version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    >
    > <xsl:eek:utput
    > method = "xml"
    > version = "1.0"
    > omit-xml-declaration = "no"
    > encoding = "UTF-8"
    > indent = "yes"
    > doctype-public = "-//W3C//DTD XHTML 1.0 Strict//EN"
    > doctype-system =
    > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"/>
    >
    >
    > <xsl:template match="/">
    > <html>
    > <xsl:apply-templates select="head"/>
    > </html>
    > </xsl:template>
    >
    > <xsl:template match="head">
    > <head>
    > <xsl:value-of select="." />
    > </head>
    > </xsl:template>
    > </xsl:transform>
    >
    > Saxon was used as the XSLT processor with the following command:
    >
    > java net.sf.saxon.Transform -o x.html index.html xsl/add-menu.xsl
    >
    >
    >
    >
    > Cheers,
    > Danx
    >
    Dimitre Novatchev, Jul 29, 2003
    #1
    1. Advertising

  2. Dimitre Novatchev

    chris Guest

    Dimitre Novatchev wrote:
    > There's no "head" element in your source.xml -- this is why the
    > xsl:apply-templates in your code does not select anything to be matched
    > against your templates and, therefore, no processing is being performed.


    But it does...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
    <html>
    <head>
    <title>t</title>
    <link rel="stylesheet" type="text/css" href="estyle.css" />
    </head>
    <body>
    </body>
    </html>
    chris, Jul 29, 2003
    #2
    1. Advertising

  3. Dimitre Novatchev

    chris Guest

    Johannes Koch wrote:

    > In your original post, there was only an empty html element. However,
    > the template for "/" applies templates for "head" child nodes of the
    > root _node_ (not the root _element_). But the only child element of the
    > root node is the html element.


    Right, thanks! I've sort of got it working, but not quite. I want to
    select everything in body be it text or element and use it as is but the
    tags are being stripped out. Is there anyway to do this?


    Chris
    chris, Jul 29, 2003
    #3
  4. * chris wrote in comp.text.xml:
    >If the DOCTYPE in the source is commented out it works fine! Any ideas?


    Namespaces. Use

    <xsl:transform ... xmlns:h = 'http://www.w3.org/1999/xhtml'>
    ...
    <xsl:template match = 'h:head'>
    ...
    Bjoern Hoehrmann, Jul 29, 2003
    #4
  5. Dimitre Novatchev

    chris Guest

    Bjoern Hoehrmann wrote:
    > * chris wrote in comp.text.xml:
    >
    >>If the DOCTYPE in the source is commented out it works fine! Any ideas?

    >
    >
    > Namespaces.


    Aha! Forgot about those!

    This works... Thankyou!

    <xsl:transform ...
    xmlns:h="http://www.w3.org/1999/xhtml">

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


    <xsl:template match="/h:">
    <html>
    <xsl:apply-templates select="/html/head" />
    <xsl:apply-templates select="/html/body" />
    </html>
    </xsl:template>

    <xsl:template match="h:head">
    <xsl:copy-of select="." />
    </xsl:template>
    chris, Jul 30, 2003
    #5
  6. Dimitre Novatchev

    chris Guest

    Dimitre Novatchev wrote:
    > Because you are using an xsl:instruction the meaning of which you obviously
    > don't know:
    >
    > xsl:namespace-alias
    >
    > is used when the task is to generate a new stylesheet and has nothing to do
    > with a simple transformation.
    >
    > You actually specidy that every node generated prefixed by "h" should be put
    > in the empty namespace.
    >
    > And this is what the XSLT processor does (following your instructions).
    >
    > You must not use a xsl:namespace-alias instruction. What was necessary is to
    > define and use the xhtml namespace when referring to xhtml elements in your
    > match patterns and XPath expressions.


    Thanks... I had to do a bit more than that, but after that was easier.
    It works now!
    chris, Jul 30, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matthew
    Replies:
    7
    Views:
    654
    Priscilla Walmsley
    Jan 7, 2005
  2. Alex Vinokur
    Replies:
    1
    Views:
    443
    Alf P. Steinbach
    Sep 27, 2004
  3. Blankdraw
    Replies:
    3
    Views:
    376
    Pieter Droogendijk
    Aug 10, 2003
  4. Peter Møllerud
    Replies:
    2
    Views:
    937
    Stefan Behnel
    Sep 9, 2006
  5. Replies:
    16
    Views:
    506
Loading...

Share This Page