template match, wich one should it be:

Discussion in 'XML' started by Tjerk Wolterink, Dec 8, 2005.

  1. I have xml inpput like this:

    <meta:empty/>


    And xsl like this:


    <xsl:template match="meta:empty">A</xsl:template>
    <xsl:template match="//meta:*">B</xsl:template>


    The namespaces meta or both bound to the same uri, so no
    problem with that.

    My Question,
    what should be outputted when i input the meta:empty element,
    A
    or
    B

    My xsl processor outputs B, but i expect it to output A
    because the match pattern "meta:empty" is more specifc then
    "//meta:*"

    What should it do?
     
    Tjerk Wolterink, Dec 8, 2005
    #1
    1. Advertising

  2. Tjerk Wolterink

    Guest

    I would have expected A to have a higher default priority than B, but
    you could try forcing B's priority to a low value to make sure the
    first template is being picked up.

    i.e.

    <xsl:template match="//meta:*" priority="-1">B</xsl:template>
     
    , Dec 8, 2005
    #2
    1. Advertising

  3. wrote:
    > I would have expected A to have a higher default priority than B, but
    > you could try forcing B's priority to a low value to make sure the
    > first template is being picked up.
    >
    > i.e.
    >
    > <xsl:template match="//meta:*" priority="-1">B</xsl:template>
    >


    But what does the W3C say? Wich one should have priority?
     
    Tjerk Wolterink, Dec 8, 2005
    #3
  4. Tjerk Wolterink

    Phil Jenkins Guest

    >From http://www.w3.org/TR/xslt#conflict

    5.5 Conflict Resolution for Template Rules

    ....

    Thus, the most common kind of pattern (a pattern that tests for a node
    with a particular type and a particular expanded-name) has priority 0.
    The next less specific kind of pattern (a pattern that tests for a node
    with a particular type and an expanded-name with a particular namespace
    URI) has priority -0.25. Patterns less specific than this (patterns
    that just tests for nodes with particular types) have priority -0.5.
    Patterns more specific than the most common kind of pattern have
    priority 0.5.

    .....

    So bascially the more specific the match - the higher the default
    priority should be
     
    Phil Jenkins, Dec 8, 2005
    #4
  5. Phil Jenkins wrote:
    >>From http://www.w3.org/TR/xslt#conflict

    >
    > 5.5 Conflict Resolution for Template Rules
    >
    > ...
    >
    > Thus, the most common kind of pattern (a pattern that tests for a node
    > with a particular type and a particular expanded-name) has priority 0.
    > The next less specific kind of pattern (a pattern that tests for a node
    > with a particular type and an expanded-name with a particular namespace
    > URI) has priority -0.25. Patterns less specific than this (patterns
    > that just tests for nodes with particular types) have priority -0.5.
    > Patterns more specific than the most common kind of pattern have
    > priority 0.5.
    >
    > ....
    >
    > So bascially the more specific the match - the higher the default
    > priority should be
    >


    So my xsl processor is doing it wrongly?

    i'm using Xalan.
     
    Tjerk Wolterink, Dec 8, 2005
    #5
  6. wrote:
    > I would have expected A to have a higher default priority than B, but
    > you could try forcing B's priority to a low value to make sure the
    > first template is being picked up.
    >
    > i.e.
    >
    > <xsl:template match="//meta:*" priority="-1">B</xsl:template>
    >


    It works with this fix, thanks.

    But i want to understand why it did'nt work...
     
    Tjerk Wolterink, Dec 8, 2005
    #6
  7. Tjerk Wolterink

    Phil Jenkins Guest

    I'm curious too :)

    Try swapping the two original (unfixed) templates around. If A now
    occurs instead of B it means that they both have the same priority;
    Xalan will pick the template that occurs last if more than one template
    has the same priority when matched - if that makes sense!

    My experience has always been to explicitly define the priority of any
    items that I want to be considered last - i'm relatively new to the
    default priority calculations, seems like extra complication having to
    rely on the processor to decide.
     
    Phil Jenkins, Dec 8, 2005
    #7
  8. In article <dn9g3g$s0$>,
    Tjerk Wolterink <> wrote:

    ><xsl:template match="meta:empty">A</xsl:template>
    ><xsl:template match="//meta:*">B</xsl:template>


    See http://www.w3.org/TR/xslt#conflict

    The first pattern has priority 0 because it has the form QName
    preceded by a ChildOrAttributeAxisSpecifier.

    The second pattern has priority 0.5 because it doesn't fall into any
    of the other listed categories. In particular, it isn't of the
    form NCName:* preceded by a ChildOrAttributeAxisSpecifier, because
    // is not a ChildOrAttributeAxisSpecifier.

    So the second rules has higher priority.

    The fact that //meta:* matches the same nodes as meta:*, which would
    have priority -0.25, is not relevant :)

    -- Richard
     
    Richard Tobin, Dec 8, 2005
    #8
  9. Tjerk Wolterink

    Phil Jenkins Guest

    Richard Tobin wrote:

    > In article <dn9g3g$s0$>,
    > Tjerk Wolterink <> wrote:
    >
    > ><xsl:template match="meta:empty">A</xsl:template>
    > ><xsl:template match="//meta:*">B</xsl:template>

    >
    > See http://www.w3.org/TR/xslt#conflict
    >
    > The first pattern has priority 0 because it has the form QName
    > preceded by a ChildOrAttributeAxisSpecifier.
    >
    > The second pattern has priority 0.5 because it doesn't fall into any
    > of the other listed categories. In particular, it isn't of the
    > form NCName:* preceded by a ChildOrAttributeAxisSpecifier, because
    > // is not a ChildOrAttributeAxisSpecifier.
    >
    > So the second rules has higher priority.
    >
    > The fact that //meta:* matches the same nodes as meta:*, which would
    > have priority -0.25, is not relevant :)
    >
    > -- Richard


    Superb answer - the W3C terminology was predictably obtuse so
    appreciate the translation:)
     
    Phil Jenkins, Dec 8, 2005
    #9
    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. bredal Jensen

    Identify wich button was pressed!

    bredal Jensen, Jul 15, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    542
    bredal Jensen
    Jul 16, 2004
  2. Fabiano
    Replies:
    1
    Views:
    530
  3. Tjerk Wolterink
    Replies:
    9
    Views:
    1,348
    Joris Gillis
    Feb 7, 2005
  4. Kent
    Replies:
    1
    Views:
    417
    Irrwahn Grausewitz
    Sep 26, 2003
  5. Carramba
    Replies:
    1
    Views:
    385
    Simon
    Oct 5, 2006
Loading...

Share This Page