 |
| 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
|
|
|
|

July 20th, 2006, 10:35 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 20th, 2006, 11:24 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 20th, 2006, 11:35 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

July 20th, 2006, 11:51 AM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
Yes.
Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
|
|

July 20th, 2006, 01:53 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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!!:)
|
|

July 20th, 2006, 02:33 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 20th, 2006, 03:16 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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>
|
|

July 20th, 2006, 04:10 PM
|
 |
Wrox Author
|
|
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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
|
|

July 20th, 2006, 04:33 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
I will def. give it a shot after all the help you provided me with! Thanks again. I will be ordering one soon.
|
|
 |