Can an XSL stylesheet have 2 root templates ?

R

Razvan

Hi,



Can an XSL stylesheet have 2 root templates ? How about 2
templates that match the same set of nodes ? Which one gets executed ?



Regards,
Razvan
 
M

Mukul Gandhi

Hi Razvan,
There are a set of rules defined by the XSLT spec for conflict
resolution for selecting which templates to select. Please do read the
spec for detailed description.

In a normal stylesheet you cannot have two template rules having the
same match pattern. This is also valid for root node. If you have 2
root templates, the processor will usually give an error.

But you may invoke the transform with an initial mode. For e.g. Saxon
provides -im option to specify the initial mode.

So you may have 2 templates for root node as below:
<xsl:template match="/">

</xsl:template>

<xsl:template match="/" mode="x" >

</xsl:template>

These templates both match the root node, but are differentiated by
the mode.

If you invoke the transformation with -im x option, the 2nd rule will
be invoked, otherwise 1st rule will be invoked.

Regards,
Mukul
 
R

Razvan

Hi Mukul,



I did not know about this "mode" parameter. Indeed, it can be
useful for selecting a template directly at runtime.



Regards,
Razvan
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,999
Messages
2,570,246
Members
46,840
Latest member
BrendanG78

Latest Threads

Top