Re: [xsl] template never matches

Subject: Re: [xsl] template never matches
From: Martin Honnen <Martin.Honnen@xxxxxx>
Date: Tue, 22 Feb 2011 13:47:03 +0100
Merrilees, David wrote:

I'm having trouble matching a named element vs using node(). Code below. Any bright ideas?

Example input:

<?xml version="1.0" encoding="utf-8"?>
<html>
   <head>
     <title>Vmtejte</title>
     <meta charset="utf-8"/>
   </head>
   <body id="home">
   </body>
</html>

XSL:

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0"
         xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
         exclude-result-prefixes="xs xsl">

         <xsl:template match="/">
                 <xsl:copy>
                         <xsl:apply-templates select="@* | node()" mode="test"/>

Here you process the child nodes of the document node with a matching template in mode "test". The only child node is the "html" element so for that element the template below is applied, it simply outputs the node with xsl:sequence but does not process any child nodes so the "head" element is never used for further processing.



         <xsl:template match="node() | @*" mode="test">
                 <!-- always matched -->
                 <xsl:sequence select="." />
         </xsl:template>

<xsl:template match="head" mode="test">

To fix that you need apply-templates but I am not really sure what you want to achieve so for further help you might want to show the output you want to create from your input sample.



--


	Martin Honnen
	http://msmvps.com/blogs/martin_honnen/

Current Thread