Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
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 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 November 3rd, 2009, 12:56 PM
Authorized User
 
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
 
Old November 3rd, 2009, 01:01 PM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 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, Data Platform Development) 2005/04 - 2013/03
My blog
The Following User Says Thank You to Martin Honnen For This Useful Post:
Hari7 (November 3rd, 2009)
 
Old November 3rd, 2009, 01:07 PM
Authorized User
 
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
Default

Thanks Martin....Its working.
 
Old November 3rd, 2009, 01:26 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 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





Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with XSLT template nelly78 XML 3 October 29th, 2009 02: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 08: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





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