|
|
 |
| XML General XML discussions. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the XML section of the Wrox p2p Programmer to Programmer discussion community. This is a community of more than 40,000 computer programmers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining our free Wrox p2p community you can post your own programming questions and respond to other programmers’ questions. Registered users also don't have to see the ads that are displayed to guests. Registration is fast, simple and absolutely free so please, join today!
Join today and post to win prizes! Post more to increase your chances of being Wrox’s top poster of the month.
|
 |

October 29th, 2009, 02:13 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Problem with XSLT template
Hi All,
I want to display part of XML using XSLT but its displaying other part of XML document also. below is my code :
XML
Code:
<?xml version="1.0" encoding="UTF-8"?>
<profile>
<users>
<user>
<firstname>John</firstname>
<lastname>Won</lastname>
</user>
</users>
<departments>
<department>Sales</department>
<department>Finance</department>
<department>Order</department>
<departments>
</profile>
XSLT:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="user">
<html>
<body>
<table>
<tr>
<td>
<font size="5" color="blue"><xsl:value-of select="firstname"></xsl:value-of></font>
<br/><br/>
<xsl:value-of select="lastname"></xsl:value-of>
</td>
</tr>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
I just want to display users information but it is displaying department as well.
How can i just display users information.#
Thanks
Nelly
|

October 29th, 2009, 02:21 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
|
|
Please note that there is a forum dedicated to XSLT where you should post such questions.
As for the problem, you can fix that by changing
Code:
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
to
Code:
<xsl:template match="/">
<xsl:apply-templates select="profile/users/user"/>
</xsl:template>
__________________
Martin Honnen
Microsoft MVP - XML
My blog
|

October 29th, 2009, 03:09 PM
|
|
Authorized User
|
|
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
|
|
Hi Martin
Thanks for your reply. It is working, is there any other way to achieve the same without giving absolute path in select.
Nelly
|

October 29th, 2009, 03:14 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
|
|
If you don't want to process the departments elements then adding
Code:
<xsl:template match="departments"/>
in your initial stylesheet would suppress any output from that element and its descendants.
__________________
Martin Honnen
Microsoft MVP - XML
My blog
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |