XML and XSLT apply-templates select -


here's xml file:

<?xml version="1.0"?>  <?xml-stylesheet type="text/xsl" href="2.xsl" ?>   <root>     <shop>         <person>              <employee>                  <name> alexis </name>                  <role> manager </role>                  <task> sales </task>              </employee>               <employee>                 <name> employee2 </name>             </employee>         </person>          <employee>             <name> blake2 </name>         </employee>      </shop>        <person>          <employee2>             <role2> supervisor </role2>              <name2> blake </name2>              <task2> control </task2>          </employee2>     </person> </root> 

here's xslt file:

<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform">    <xsl:template match="root">  <html><head></head>  <body> start of root in xslt <p/> <xsl:apply-templates select="person" /> <p/>  end of root in xslt  </body>  </html>  </xsl:template>     <xsl:template match="shop"> "step 1 start" <xsl:apply-templates select="*/*"/> "step 1 done" <p/> </xsl:template>     <xsl:template match="employee">  <u> <xsl:apply-templates select="name"/> </u>  (task: <xsl:apply-templates select="task"/>)  <br></br>  </xsl:template>    </xsl:stylesheet> 

the output is:

start of root in xslt

supervisor blake control

end of root in xslt

my question is, why isn't alexis , employee2 part of output? they're both under <person> element.....

<xsl:template match="root"> applied <root> element. in there, <xsl:apply-templates select="person" /> selects <person> element immediate child of current node (the root element <root>). there no template defined <person> itself, xslt's default behavior executed means text nodes copied.

the other templates not executed @ all, there no <shop> or <employee> elements on root level (relative document itself), , templates not invoked via <apply-templates>, either.

to answer question more explicitly, first <person> element not selected because nested in element, <apply-templates> instruction selects <person> elements directly visible in current node.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -