Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > Re: No output? What's wrong?

Reply
Thread Tools

Re: No output? What's wrong?

 
 
Dimitre Novatchev
Guest
Posts: n/a
 
      07-29-2003
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"
> xmlnssl="http://www.w3.org/1999/XSL/Transform">
>
> <xslutput
> 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
>



 
Reply With Quote
 
 
 
 
chris
Guest
Posts: n/a
 
      07-29-2003
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>

 
Reply With Quote
 
 
 
 
chris
Guest
Posts: n/a
 
      07-29-2003
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

 
Reply With Quote
 
Bjoern Hoehrmann
Guest
Posts: n/a
 
      07-29-2003
* 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'>
...
 
Reply With Quote
 
chris
Guest
Posts: n/a
 
      07-29-2003
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>

 
Reply With Quote
 
chris
Guest
Posts: n/a
 
      07-30-2003
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!

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57