Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Jun 1st, 2006, 4:10 PM   #1
gtavercetti
Newbie
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0 gtavercetti is on a distinguished road
apply-templates

Hell, I am relatively new to XML/XSL. I am having a problem understanding the results of some test I have been doing. I have been staring at this very basic code for hours so I am sure the answer is quite simple, but any help would be appreciated. I have one XML/XSL pair:

sal.xml

<?xml version="1.0" encoding="iso-8859-1" ?>
<?xml-stylesheet type="text/xsl" href="styles/file_edit.xsl"?>
<partial>
<title value="Salamander - Instruments" />
<header id="small_header" />
<user>
<status>regular</status>
</user>
<instruments>
<instrument>
<anchor>
<src>index.php</src>
<text>ATUS</text>
<param value="task=inst_files" />
<param value="inst_id=5" />
</anchor>
<description>First</description>
</instrument>
<instrument>
<anchor>
<href>index.php</href>
<text>Test</text>
<param value="task=inst_files" />
<param value="inst_id=6" />
</anchor>
<description>Second</description>
</instrument>
</instruments>
</partial>

file_edit.xsl

<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl: output method="html"/>
<!--<xsl:include href="main.xsl" />-->


<xsl:template match="/">
<div>
<xsl:apply-templates/>
</div>
</xsl:template>


<xsl:template match="partial">
<body>
<xsl:apply-templates/>
</body>
</xsl:template>

<xsl:template match="user">
Found
</xsl:template>

</xsl:stylesheet>

Which results in the following output:

Found index.php ATUS First index.php Test Second

Why are the contents of the nodes FOLLOWING <user> (<instruments>) being printed when their are no templates which apply directly to them? I thought apply-template only applied to the direct children of the current node.

In anycase, how to I get it to only print 'Found?'

Thanks
gtavercetti is offline   Reply With Quote
Old Jun 1st, 2006, 4:19 PM   #2
gtavercetti
Newbie
 
Join Date: Jun 2006
Posts: 2
Rep Power: 0 gtavercetti is on a distinguished road
Okay, I found out how to just show 'Found', but I would still appreciate if someone could tell me why apply-templates prints out everything after the 'user' node.
gtavercetti is offline   Reply With Quote
Old Jun 1st, 2006, 6:04 PM   #3
Arevos
Programming Guru
 
Arevos's Avatar
 
Join Date: Aug 2005
Location: England
Posts: 1,499
Rep Power: 5 Arevos is on a distinguished road
Quote:
Originally Posted by gtavercetti
Okay, I found out how to just show 'Found', but I would still appreciate if someone could tell me why apply-templates prints out everything after the 'user' node.
I'm not quite sure what you mean by this. Could you give an example to illustrate what you mean?

Also, encase your XML in code tags.
Arevos is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:25 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC