Can an XSL stylesheet have 2 root templates ?

Discussion in 'XML' started by Razvan, Mar 28, 2005.

  1. Razvan

    Razvan Guest

    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
    Razvan, Mar 28, 2005
    #1
    1. Advertising

  2. Razvan

    Mukul Gandhi Guest

    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

    "Razvan" <> wrote in message news:<>...
    > 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
    Mukul Gandhi, Mar 29, 2005
    #2
    1. Advertising

  3. Razvan

    Razvan Guest

    Hi Mukul,



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



    Regards,
    Razvan


    Mukul Gandhi wrote:
    > 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
    >
    > "Razvan" <> wrote in message

    news:<>...
    > > 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
    Razvan, Mar 29, 2005
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Steven An
    Replies:
    1
    Views:
    490
    Martin Honnen
    Nov 23, 2004
  2. Thomas Sommer
    Replies:
    0
    Views:
    422
    Thomas Sommer
    Nov 25, 2004
  3. MC
    Replies:
    1
    Views:
    7,232
    David Carlisle
    Mar 24, 2005
  4. Replies:
    0
    Views:
    519
  5. JKop
    Replies:
    3
    Views:
    449
Loading...

Share This Page