Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old October 29th, 2009, 01:13 PM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
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
 
Old October 29th, 2009, 01:21 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old October 29th, 2009, 02:09 PM
Authorized User
 
Join Date: Apr 2008
Posts: 85
Thanks: 10
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
 
Old October 29th, 2009, 02:14 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
nelly78 (October 29th, 2009)





Similar Threads
Thread Thread Starter Forum Replies Last Post
XSLT Template oornelas_Ca XSLT 7 August 15th, 2009 10: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 06:41 AM
Problem in passing parameter to xslt template uttamgarg XSLT 0 April 20th, 2006 09:53 AM
XSLT Template error again bmains XSLT 4 December 19th, 2003 11:17 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.