|
|
 |
| 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.
|
 |

November 3rd, 2009, 12:56 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
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
|

November 3rd, 2009, 01:01 PM
|
|
Friend of Wrox
|
|
Join Date: Nov 2007
Location: Germany
Posts: 655
Thanks: 0
Thanked 98 Times in 97 Posts
|
|
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
|
|
The Following User Says Thank You to Martin Honnen For This Useful Post:
|
Hari7 (November 3rd, 2009) |

November 3rd, 2009, 01:07 PM
|
|
Registered User
|
|
Join Date: Oct 2009
Posts: 15
Thanks: 3
Thanked 0 Times in 0 Posts
|
|
Thanks Martin....Its working.
|

November 3rd, 2009, 01:26 PM
|
 |
Wrox Author
Points: 12,735, Level: 48 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 3,923
Thanks: 0
Thanked 82 Times in 80 Posts
|
|
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
|
| 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
|
|
|
|
 |