Thread: apply-templates
View Single Post
Old Jun 1st, 2006, 3: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