Programming Forums

Programming Forums (http://www.programmingforums.org/forumindex.php)
-   XML (http://www.programmingforums.org/forum28.html)
-   -   apply-templates (http://www.programmingforums.org/showthread.php?t=10122)

gtavercetti Jun 1st, 2006 3:10 PM

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 Jun 1st, 2006 3:19 PM

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.

Arevos Jun 1st, 2006 5:04 PM

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.


All times are GMT -5. The time now is 9:46 PM.

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