Unique attributes and preceding-sibling question

Discussion in 'XML' started by johkar, Oct 20, 2006.

  1. johkar

    johkar Guest

    I am having trouble figuring out how to use preceding sibling when I am
    already on the node. I have a feeling that you cannot use
    preceding-sibling on an attribute, but I can't figure out the syntax.

    XML:
    <leftcol>
    <nav type="extra" location="top">
    <boxlink href="#">Link 1</boxlink>
    </nav>
    <nav type="extra" location="bottom">
    <boxlink href="#">Link 1</boxlink>
    </nav>
    <nav type="right">
    <boxlink href="#">Link 1</boxlink>
    </nav>
    </leftcol>

    <xsl:apply-templates select="/leftcol/nav" />

    <xsl:if test="@type='extra' and not(@type=preceding-sibling::./@type)">
    <!-- More XSL -->
    </xsl:if>

    The goal is to only output one nav with a type of extra.
    johkar, Oct 20, 2006
    #1
    1. Advertising

  2. The problem is your use of ., which is not correct syntax.

    You want to look at the preceeding <nav>'s type attribute, so:

    <xsl:if test="@type='extra' and not(@type=preceding-sibling::nav/@type)">



    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Oct 20, 2006
    #2
    1. Advertising

  3. johkar

    roy axenov Guest

    johkar wrote:
    > XML:
    > <leftcol>
    > <nav type="extra" location="top">
    > <boxlink href="#">Link 1</boxlink>
    > </nav>
    > <nav type="extra" location="bottom">
    > <boxlink href="#">Link 1</boxlink>
    > </nav>
    > <nav type="right">
    > <boxlink href="#">Link 1</boxlink>
    > </nav>
    > </leftcol>
    >
    > <xsl:apply-templates select="/leftcol/nav"/>
    >
    > <xsl:if test="@type='extra' and
    > not(@type=preceding-sibling::./@type)">


    That's just plain wrong. '.' is a shortcut for the self
    axis, so basically you're trying to use two axes at the
    same time.

    > <!-- More XSL -->
    > </xsl:if>


    Generally, if you're asking for help, it's a good idea to
    post something that people can stuff into their XSLT
    processors right away and see what happens.

    > The goal is to only output one nav with a type of extra.


    So don't use if. *Select* only one nav. Or *match* only one
    nav. That's what predicates are for:

    <xsl:apply-templates
    select="/leftcol/nav[@type='extra'][1]"/>

    --
    roy axenov
    roy axenov, Oct 20, 2006
    #3
  4. johkar

    johkar Guest

    Joseph Kesselman wrote:
    > You want to look at the preceeding <nav>'s type attribute, so:
    >
    > <xsl:if test="@type='extra' and not(@type=preceding-sibling::nav/@type)">


    Thank you for your help.
    johkar, Oct 21, 2006
    #4
  5. johkar

    johkar Guest

    roy axenov wrote:
    > So don't use if. *Select* only one nav. Or *match* only one
    > nav. That's what predicates are for:
    >
    > <xsl:apply-templates
    > select="/leftcol/nav[@type='extra'][1]"/>


    Thanks for the great tip.
    johkar, Oct 21, 2006
    #5
    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. Chris
    Replies:
    5
    Views:
    1,857
    Chris
    Apr 19, 2005
  2. Replies:
    11
    Views:
    649
    Fredrik Lundh
    Jan 23, 2006
  3. Matt Waite
    Replies:
    4
    Views:
    351
    Matt Waite
    Feb 1, 2007
  4. Red
    Replies:
    2
    Views:
    1,215
    Pavel Lepin
    May 9, 2007
  5. ToshiBoy
    Replies:
    6
    Views:
    842
    ToshiBoy
    Aug 12, 2008
Loading...

Share This Page