p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XML
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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.

Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 29th, 2009, 02:13 PM
Authorized User
Points: 156, Level: 3
Points: 156, Level: 3 Points: 156, Level: 3 Points: 156, Level: 3
Activity: 37%
Activity: 37% Activity: 37% Activity: 37%
 
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
Default 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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old October 29th, 2009, 02:21 PM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #3 (permalink)  
Old October 29th, 2009, 03:09 PM
Authorized User
Points: 156, Level: 3
Points: 156, Level: 3 Points: 156, Level: 3 Points: 156, Level: 3
Activity: 37%
Activity: 37% Activity: 37% Activity: 37%
 
Join Date: Apr 2008
Location: , , .
Posts: 36
Thanks: 5
Thanked 0 Times in 0 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old October 29th, 2009, 03:14 PM
Friend of Wrox
Points: 3,131, Level: 23
Points: 3,131, Level: 23 Points: 3,131, Level: 23 Points: 3,131, Level: 23
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
Default

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
The Following User Says Thank You to Martin Honnen For This Useful Post:
nelly78 (October 29th, 2009)
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Template oornelas_Ca XSLT 7 August 15th, 2009 11:11 AM
Stumped on XSLT template hayedid XSLT 8 December 19th, 2007 02:14 PM
XSLT Template Issue saravanan.k XSLT 2 March 14th, 2007 07:41 AM
Problem in passing parameter to xslt template uttamgarg XSLT 0 April 20th, 2006 10:53 AM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM



All times are GMT -4. The time now is 02:03 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
© 2008 Wiley Publishing, Inc