• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Ron McLeod
  • paul wheaton
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
  • Himai Minh
Bartenders:

Need help in knowing the error.

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Here i would like to know answers for my queries, please help me in clearing my doubts.
*****************
XML File
*****************
<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="kiran.xsl"?>
<person>
<details>
<name>Lokesh</name>
<address>Hyderabad</address>
</details>
<details>
<name>Narayana</name>
<address>Secunderabad</address>
</details>
<details>
<name>Kiran</name>
<address>Khairatabad</address>
</details>
</person>

******************
XSL File
******************
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="person">
<html>
<head>
<title>Friends List</title>
</head>
<body>
<table border="1" cellspacing="1" cellpadding="1" align="center" width="50%">
<tr>
<th align="left" width="50%">Name</th>
<th align="left" width="50%">Address</th>
</tr>
<xsl:for-each select="details">
<tr>
<td align="left" width="50%"><xsl:value-of select="name"/></td>
<td align="left" width="50%"><xsl:value-of select="address"/></td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

****************
My Queries
****************
1) Why should i only specify http://www.w3.org/TR/WD-xsl as a namespace and why not others.
2) I am not able to view my xml file if i replace "/" in the first template with the root element, what is the reason behind it?
Thanx in advance.
Loke.
 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi Loke
Regarding ur first query i.e of xslt name space
XSLT processors must use the XML namespaces mechanism [XML Names] to recognize elements and attributes from this namespace. Elements from the XSLT namespace are recognized only in the stylesheet not in the source document. Vendors must not extend the XSLT namespace with additional elements or attributes. Instead, any extension must be in a separate namespace. Any namespace that is used for additional instruction elements must be identified by means of the extension element mechanism.
For example for java it is
xmlns:java="http://xml.apache.org/xslt/java"
I tried ur's second query and it gave me the perfect result.
Bye
Pankaj
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you don't mind me asking: which XSLT processor are you using? Version one of the XSLT specification specifies that the namespace URI should be "http://www.w3.org/1999/XSL/Transform". The namespace URI you have is quite old. For instance, the "wd" of the namespace you have means "working draft". XSLT is a full specification since November 1999. Actually, if you don't get anything from the XML document if you do not match "/" in one of the templates, then you are probably using one of the older Microsoft XSLT processors. For those processors, you must specify the default templates as well. That is why if you don't specify "/", you won't be able to process the root of the document (not to be confused with the root element of the document, "person" in your case). And of course, since everything is under the root element, you won't be able to process the rest of the document as well. My advice is to get a more up-to-date XSLT processor.

------------------
Khun Yee Fung
Author of XSLT: Working with XML and HTML
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic