Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

XML data not displaying with XSL  RSS feed

 
Chris Behr
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!