Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2006, 10:35 AM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT Decleration Error.

Hello all,

I am trying to have a .xsl stylesheet read and parse an XHTML file and output a XHTML file. I keep getting a decleration error. Below is the error and my code. Any help would be greatly appreciated.

Error:

 XSLT Error (javax.xml.transform.TransformerConfigurationExcep ti
 on): javax.xml.transform.TransformerException:
 javax.xml.transform.TransformerEx
 ception: stylesheet requires attribute: version

Code:

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/xhtml' version='1.0'>
<xsl:output method='xhtml' indent='no' include-content-type='no'
     doctype-public="-//W3C//DTD XHTML 1.1//EN"
     doctype-system="DTD/xhtml11.dtd" />

Thanks again.

 
Old July 20th, 2006, 11:24 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

It's a lousy error message, but your mistake is that you've bound the "xsl" prefix to the XHTML namespace instead of the XSLT namespace.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2006, 11:35 AM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you for the quick response.

Forgive me for my ignorance for I am not that good with namespaces. If I change my code from:

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/xhtml' version='1.0'>

to

<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

Is this what you were refering to?

 
Old July 20th, 2006, 11:51 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Yes.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2006, 01:53 PM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks again! I got it working now I have one other problem but I will post here to see if anyone else has a solution.


I am trying to change an XHTML font tag to a span tag.

Below is my code:

<xsl:template match="font">
 <xsl:element name="span">
  <xsl:attribute name="class">small</xsl:attribute>
  <xsl:copy-of select="local-name() != 'font'" />
  </xsl:element>
</xsl:template>

What is happening is I am replacing the tags fine but I am not getting the text between my original tags I am replacing.

For example the HTML code below
<html>
<head></head>
<body>
test
</body>

</html>

has this output

<html>
<head></head>
<body>
<span class="small">false</span>
</body>

</html>

So I am loosing the content between the tags.

Thanks in advance everyone!!:)

 
Old July 20th, 2006, 02:33 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

The value of

local-name() != 'font'

is a boolean which you are copying to your output.

I imagine you want *[local-name() != 'font'] or something similar.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2006, 03:16 PM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will just want to post one more time I don't want to take all of your time from others.

Here is the portion of code I am having trouble on

<xsl:template match="font">
   <xsl:element name="span">
   <xsl:attribute name="class">small</xsl:attribute>
    <xsl:copy-of select="." />
   </xsl:element>
</xsl:template>

This renders output of the following

<html>
 <head />
 <body>
 <span class="small">test</span>
 </body>
</html>

I am trying to keep all of this but the open and close font face tags. I do want the data (in this case 'test') to appear. Below is my desired output.

<html>
 <head />
 <body>
 <span class="small">test</span>
 </body>
</html>


 
Old July 20th, 2006, 04:10 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

To copy the children of the context node but not the context node itself, use <xsl:copy-of select="child::node()"/>

P.S: I'd recommend my book...

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old July 20th, 2006, 04:33 PM
Authorized User
 
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I will def. give it a shot after all the help you provided me with! Thanks again. I will be ordering one soon.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Error with XSLT deekshan XSLT 2 July 28th, 2008 03:53 AM
XSLT -XPATH Error xslspy XSLT 1 October 27th, 2005 03:24 AM
Compier Error: procedure decleration does'nt match haahoou Beginning VB 6 2 January 20th, 2004 03:10 AM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM
How to generate an Error message from XSLT srini XSLT 2 December 16th, 2003 10:50 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.