It's not a secret anymore!*
The moose likes XML and Related Technologies and the fly likes XML data not displaying with XSL Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML data not displaying with XSL" Watch "XML data not displaying with XSL" New topic
Author

XML data not displaying with XSL

Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
I have just started learning XML so bear with me. I have a xml document that I created and want to use a stylesheet to display it in html but it doesn't seem to be working. Here is the xml file:
<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="XSL\myXSL.xsl" type="text/xsl"?>
<GstBk:Book xmlns:GstBk="http://www.testurl.com">
<GstBk:Guest>
<GstBk:Address>
<GstBk:Name>John Doe</GstBk:Name><GstBk:From>Anywhere USA</GstBk:From>
</GstBk:Address>
</GstBk:Guest>
</GstBk:Book>
And here is the xsl document:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:GstBk="http://www.testurl.com"
version="1.0"
>
<xsl:template match="GstBk:Book">
<html>
<head>
<title>Guest Book</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="GstBk:Guest">
Name = <xsl:value-of select="GstBk:Name" />
</xsl:template>
</xsl:stylesheet>
But the only data I get on the browser is:
Name =
Can anyone see something wrong with my files? I have downloaded examples from the net and they seem to work. I even compared them to my files and can't see anything obviously different. Any ideas?
Thanks
Sumedh
Greenhorn

Joined: Aug 02, 2001
Posts: 3
Chris,
You need to have "GstBk:Address/GstBk:Name" instead of "GstBk:Name".
<xsl:template match="GstBk:Guest">
Name = <xsl:value-of select="GstBk:Address/GstBk:Name" />
</xsl:template>
-Sumedh
Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
It still doesn't seem to be working. I changed my XSL to:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:GstBk="http://www.testurl.com"
version="1.0"
>
<xsl:template match="GstBk:Book">
<html>
<head>
<title>Guest Book</title>
</head>
<body>
<xsl:apply-templates />
</body>
</html>
</xsl:template>
<xsl:template match="GstBk:Guest">
Full Name = <xsl:value-of select="GstBk:Address/GstBk:Name" />
</xsl:template>

</xsl:stylesheet>
And all I get is:
Full Name =
Do you have any other ideas on what I might be doing wrong?
Thanks
Kris Decker
Ranch Hand

Joined: Jul 25, 2001
Posts: 38
I have found varying behavior with XSL depending on whether I use XML Spy or IE.
Also, the Namespace will have an impact
[This message has been edited by Kris Decker (edited August 29, 2001).]
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi Chris,
What transformation engine are you using? For me, the fixed example works fine with Xalan2-Java and with Microsoft IE5.5.
As an alternative to Sumedh's fix, you can also use:
<xsl:value-of select=".//GstBk:Name" />
This selects all the descending nodes (.//GstBk:Name is a shortcut for self::node()/descendant-or-self::node()/GstBk:Name)
Cheers,
Beno�t
Chris Behr
Greenhorn

Joined: Jun 12, 2001
Posts: 17
I am running thru a service provider but as far as I can tell they are using apache cocoon 2 if that means anything to you.
Darryl Andrew
Greenhorn

Joined: Jun 21, 2001
Posts: 12
Originally posted by Beno�t d'Oncieu:
Hi Chris,
What transformation engine are you using? For me, the fixed example works fine with Xalan2-Java and with Microsoft IE5.5.
As an alternative to Sumedh's fix, you can also use:
<xsl:value-of select=".//GstBk:Name" />
This selects all the descending nodes (.//GstBk:Name is a shortcut for self::node()/descendant-or-self::node()/GstBk:Name)
Cheers,
Beno�t

Hi, since u r using xalan2, can u pls tell me what are the path to use? i include xalan2.jar, xerces.jar, xalanservlet.jar and servlet.jar in my path when running the servlet example provided in xml.apache.org using xalan2.jar. But i'm still experiencing java.lang.NoClassDefFoundError error
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML data not displaying with XSL