This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Identity Transform and Default Templates, I think...


> I think that my question boils down to template application - when does a
> particular template get applied?

when you apply templates to a set of nodes, and teh given template is
the highest priority template that matches one of the nodes in the set.


> When does the default template get applied?
when you apply templates to a node and no other template matches.

> <xsl:sytlesheet>
if that is your real stylesheet you should get no output at all as you
need to declare the xsl: namespace prefix is XSLT and that you are using
version="1.0" of XSLT.



  <!-- match the root and select the C3PO template -->
  <xsl:template match="/">
    <xsl:apply-templates select="C3PO"/>
  </xsl:template>


No. It selects the C3PO _node_ . select= does not refer to templates.
If the template   <xsl:template match="C3PO"> turns out to be the
highest priority template that matches a c3PO element then it will run.

Actuallt that template isn't needed at all as the default template
would do the same thing in this case.

      <xsl:attribute name="id">
        <xsl:value-of select="attribute::id"/>
      </xsl:attribute>

that's fine but could more simply be written
<xsl:copy-of select="@id"/>

>  But now I'd like to make it a bit more flexible.
OK replace each of your
<xsl:apply-templates select=xxx"/>
by
<xsl:apply-templates />
Then you will apply templates to all child nodes not just the ones you
have named.

as you haven't any templates for teh new elements the default template
will run (which just does nothing on the element and recurses on the
children) 

You want to copy these other elements so a template that matches
ecverything (unless a higher priority template overrides)

<xsl:template  match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>

and you should be done.

you didn't get the head element in your example as your template for
BD is only applying elements to TR children. If you add this * template
and then remove the select attribute so the BD template applies
templates to all children you should be fine.

David

_____________________________________________________________________
This message has been checked for all known viruses by Star Internet
delivered through the MessageLabs Virus Scanning Service. For further
information visit http://www.star.net.uk/stats.asp or alternatively call
Star Internet for details on the Virus Scanning Service.

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]