Skip to main content
1-Visitor
September 28, 2010
Question

Reverse Xpath expression

  • September 28, 2010
  • 1 reply
  • 4741 views

I need to create a xpath-expression in Styler that finds at the latest section element with a specific value on it´s type attribute. The section element can be nestled so I cant predict where the type attribute was set the last time. I need to do this so that I know what derived section type I have.

Example of context:

  • section/section@type='xx'/section
  • section/section/section/section@type='xx'
  • section@type='xy'/section@type='xx'/section/section

In all the above I need to know the latest section where type was set.

My thought was to create the following condition (and repeat it for other type values):

parent::section[@type='xx']

Unfortunatly it doesn´t seem to do the trick and I have spoken to others working with Styler that says it is hard to create working reverse expressions in Styler.

Has anyone had any experience of this or perhaps even a solution?

Greatful for all answers!

    1 reply

    17-Peridot
    September 30, 2010

    Johan

    Not sure I fully understand your request, but did you try parent::section[@type='xx'][position()=last()]?

    If you provide example, I could try to give a more precise answer.

    1-Visitor
    October 1, 2010

    That is a good idea but I dont seem to get the expected response from Styler. I must say that it seems as if the parent axes command dont work properly. Do you have experience using parent calls in Styler?

    I will try to create a better example.

    I have three different page layouts that is used (lets call them lay1, lay2 och lay3). These page layouts can be set for each section using the type attribute (the type attribute will list lay1, lay2 and lay3).

    If I specifiy a type attribute on a section, nestled sections will derive the same page layout unless the type attribute is set for nestled sections as well.

    Example:

    section@type='lay1'/section/section

    The first section will use lay1, nestled sections will also use lay1.

    section@type='lay1'/section/section@type='lay2'/section

    The first section will use lay1, so will the first nestled section. After that there will be two nestled sections using lay2.

    It becomes more complicated when you add elements in the last section that needs to be formatted in other ways depending on the derived section type.

    Example:


    section@type='lay1'/section/section@type='lay2'/section/table

    In this case I want to change the indent for the table depending on the derived section type (lay2).

    Since I have problems using parent I believe I need to find another way. If I use ancestor it will point to the first section giving me lay1.

    Currently im working with a lot of variants of "../../@type='lay2'" to get where I want but I am certain that it isn't the best way.

    So basically what I am looking for is a xpath-command that will navigate from current context to the first section where the attribute type has been set.

    17-Peridot
    October 1, 2010

    Johan

    Check the attached video. Is it what you're looking for?