Search

hello,

Im following this page to learn xslt : http://edutechwiki.unige.ch/en/XSLT_Tutorial_-_Basics

So I made a two files named hello.xml and hello.xsl with xmlcopyeditor. Both files are well-formed.

But when I do xsl transform to make the html page I see this message: Cannot transform: Error at line 7, column 12: Failed to parse QName 'xsl:'

Here are both files.

hello.xsl :

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:template match="page">
    <html>
    <head>
    <title>
      <xsl: value-of-select="title" />
    </title>
    </head>
    <body bgcolor="#ffffff">
      <xsl:apply-templates./>
     </body>    
     </html>
  </xsl:template>

  <xsl:template match="title">
    <h1 align="center"><xsl:apply-templates /></h1>  
  </xsl:template>

  <xsl:template match="content">
    <p align="center"><xsl:apply-templates /></p>
  </xsl:template>

</xsl:stylesheet>

hello.xml :

<?xml version="1.0" encoding="UTF-8"?>
  <?xml-stylesheet href="hello.xsl" type="text/xsl"?>
  <page>
    <title>Hello</title>
    <content>Here is some content</content>
 </page>

I did type exactly what in the page. Can anyone help me find out what went wrong here?

Roelof

Edit: updated code to fix forum formatting problem (Nick)

Cannot transform: Error at line 7, column 12: Failed to parse QName 'xsl:'

The clue is in the error message :-)

On line 7 of hello.xsl you have:

      <xsl: value-of-select="title" />

Column 12 (the 12th character on the line) is the space between xsl: and value-of. This isn't valid XML, so remove the space and you should be good.

For clarity: element names in XML (and HTML) cannot contain spaces. XSLT is actually just XML, and all of its elements are prefixed with the xsl namespace. So the value-of element is an XML element named: <value-of ... />, but with an XSLT namespace: <xsl:value-of .../>. Either way, it cannot contain spaces :-)

Thanks

I changed it to this : <xsl:value-of-select="title" /> but now I get this message:

Error at line 7, columm 27 : not well formed (invalid token)

Roelof

Found that problem : it has to be

But I see another problem: When I do a transform I see this as output :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

it is

<xsl:value-of select="title" />

without - (dash) before select.

Oke I found that already. Somehow my code did not go the right way.

The output I get you can find here : http://pastebin.com/2haf5kzT

So as you can see the whole body has disappear.

Roelof

You need to define a template for / as that's your root node (it always is). From there on you can go and select page.

oke,

Then the tutorial is not right. They don't talk about a template for /

Roelof

No one a idea what went wrong or can I better forget about this tutorial.

Roelof

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.3-5.6 or 7.0-7.3
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.5 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details