xsl-list
[Top] [All Lists]

Re: [xsl] template never matches

2011-02-22 06:47:26
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>Vítejte</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/

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>