p2p.wrox.com Forums

Need to download code?

View our list of code downloads.


Go Back   p2p.wrox.com Forums > XML > XSLT
I forgot my password Register Now
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.

Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT 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 November 3rd, 2009, 12:56 PM
Registered User
Points: 70, Level: 1
Points: 70, Level: 1 Points: 70, Level: 1 Points: 70, Level: 1
Activity: 37%
Activity: 37% Activity: 37% Activity: 37%
 
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Default Problem with template

Hi All,

Below is the XMl and Xslt i am having problem with template.

XML

Code:
<?xml version="1.0" encoding="UTF-8"?>


  <Sheets>
	<Sheet Id="Sh1">
                  <Main Id="M1">
	         <current>	
                         <title>World</title>
                         <story>Hello world</story>
	         </current>
	     </Main>
	     <sport Id="S1">
                      <current>
		<title>Boxing</title>
                          <story>Boxing between A and B</story>
	         </current>
                 </sport>
	</Sheet>
  </Sheets>
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="sheet">
        <xsl:if test="@id='Sh1'">
            <xsl:apply-templates select="/*[@Id='M1']"/>
        </xsl:if> 
    </xsl:template>


    <xsl:template match="current">
        <xsl:value-of select="title">
        <br/>
        <xsl:value-of select="story">
    </xsl:template>


</xsl:stylesheet>
Below part is not returning the desired result.which should Select Main element.

'<xsl:apply-templates select="/*[@Id='M1']"/>'

I have tired executing Xpath directly in the Editor and its working fine :

/sheets/sheet[@Id='Sh1']/*[@Id='Main']

Can u tell me where i am doing wrong.

Thanks
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #2 (permalink)  
Old November 3rd, 2009, 01:01 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

You need
Code:
<xsl:apply-templates select="*[@Id='M1']"/>
or
Code:
<xsl:apply-templates select="./*[@Id='M1']"/>
Also note that in the XML you have 'Sheet', starting with an upper case 'S', while you match="sheet" only matches 'sheet' elements starting with a lower case 's'.
__________________
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:
Hari7 (November 3rd, 2009)
  #3 (permalink)  
Old November 3rd, 2009, 01:07 PM
Registered User
Points: 70, Level: 1
Points: 70, Level: 1 Points: 70, Level: 1 Points: 70, Level: 1
Activity: 37%
Activity: 37% Activity: 37% Activity: 37%
 
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks Martin....Its working.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
  #4 (permalink)  
Old November 3rd, 2009, 01:26 PM
mhkay's Avatar
Wrox Author
Points: 12,735, Level: 48
Points: 12,735, Level: 48 Points: 12,735, Level: 48 Points: 12,735, Level: 48
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
Default

You also seem to be confused as to whether it is "sheet" or "Sheet". XML is case-sensitive.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Reddit!
Reply With Quote
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
Problem with XSLT template nelly78 XML 3 October 29th, 2009 03:14 PM
Problem in Recursive applying template ismomo XSLT 3 December 29th, 2007 11:35 PM
xsl:template problem mickhughes XSLT 1 August 16th, 2007 09:40 AM
xsl template concat problem nambati XSLT 5 January 31st, 2005 03:43 PM
Datagrid template column problem lore6673 ASP.NET 1.x and 2.0 Application Design 1 December 3rd, 2003 11:05 AM



All times are GMT -4. The time now is 11:00 PM.


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