Skip to main content
1-Visitor
October 12, 2011
Question

How to Capture Generated Section Number in Styler?

  • October 12, 2011
  • 14 replies
  • 2243 views

Hi all,


I am a beginner, a bit overwhelmed with creating my first stylesheet. I know I will have to use FOSI eventually but I am trying to get as much done in Styler first. I was wondering if there is an XPath override to capture the previous element's generated text title number in Styler? I was only able to retreive the title without the number.My element title numbers are restarting at 1 and I would like them to +1 from the previous element's number.


Also, can one output the title number after the element content in Styler, or will I have to do a FOSI edit with a text variable?


I'm using 5.3.


Thanks for any help!


Regards, Caroline

    14 replies

    16-Pearl
    October 12, 2011
    Hi Caroline,



    If you use the built-in Styler features you shouldn't need to worry about
    all this. Setup divisions and titles and I think it will auto-number them
    for you. For cross-references you can set those up to grab the numbering
    too.



    A good point of reference is always the built-in styler stylesheets. Try
    making a new file with the Docbook (axdocbook) sample, then open Styler and
    have a poke around. That should give you some ideas.



    -Gareth


    cleccese1-VisitorAuthor
    1-Visitor
    October 12, 2011

    Hi Gareth,


    Thanks for your reply. I have tried using divisions and formal blocks, but these are sibling elements and keep restarting their numbering at 1. That is why I was trying to capture the generated label number from the previous sibling element.

    1-Visitor
    October 12, 2011
    I suspect you can fix this by changing the "restart" setting in the
    "numbering details" dialog, accessible from the "Gentext" tab for the
    title of the item in question. That said, I'm still not sure I
    completely understand what's happening in your scenario, given your
    fairly generic description. Can you provide some more concrete
    details, like a snippet of sample input and the numbering you'd expect
    for each item? If the numbering should restart at certain boundaries
    (such as <chapter>), try to include that in the snippet, as well.

    -Brandon 🙂


    On Wed, Oct 12, 2011 at 3:52 PM, Caroline Leccese
    <caroline@thecodesource.net> wrote:
    > Hi Gareth,
    >
    > Thanks for your reply. I have tried using divisions and formal blocks, but
    > these are sibling elements and keep restarting their numbering at 1. That is
    > why I was trying to capture the generated label number from the previous
    > sibling element.
    >
    > -----End Original Message-----
    cleccese1-VisitorAuthor
    1-Visitor
    October 13, 2011

    Hi Brandon,


    Thanks for your reply. Going by the PDF I was given of finished output which is my only reference, Foreword Title is labeled 10, List of Related Publications Title is labeled 8 and Acronyms Title is labeled 9. Then Purpose Title is labeled 1, Scope is 2 and Manual Structure is 3.


    If I make <forewordwp> a Division and <foreword> a Formal Block, Foreword Title is labeled 4. If I make <foreword> a Division, it restarts at 1. No matter how I've set up the rest of the elements, as either Formal Blocks or Divisions, the title numbers are always 1 for everything below Foreword. So I thought there might be an XPath override for the current level I could enter in the Title Number dialog box that would grab the label # for Purpose which I could +1 to get 2 for the Scope Title, and 3 for Manual Structure and so on. I tried using the restart numbering option but was unsuccessful.


    Thanks for any help!


    Caroline


    -----------------------------------------------------------------------------------------


    <forewordwp>

    <foreword>
    <para0>
    <title>FOREWORD</title>
    </para0>
    <lrp>
    <title>LIST OF RELATED PUBLICATIONS</title>
    </lrp>
    <abbrsect>
    <title>ACRONYMS AND ABBREVIATIONS</title>
    <para></para>
    <acronymlist>
    <term></term>
    <def></def>
    </acronymlist>
    </abbrsect>
    </foreword>

    <purpose>
    <title>PURPOSE</title>
    </purpose>

    <scope>
    <title>SCOPE</title>
    </scope>

    <manstru>
    <title>MANUAL STRUCTURE</title>
    </manstru>

    </forewordwp>

    1-Visitor
    October 13, 2011
    With values like 10, 8 and 9, it's really not clear to me what the
    rule is for the first few items, but the last three certainly seem to
    be numbered all in the same sequence, which restarts at the
    "forewordwp". You're right that you'll need an XPath override on the
    title context for each of these three. You can't do a "previous + 1"
    operation, but you also don't need to. As long as these elements will
    always be siblings, you can use something like this (these two are
    equivalent, so use whichever one you prefer):

    count(preceding-sibling::purpose | preceding-sibling::scope |
    preceding-sibling::manstru) + 1
    count(preceding-sibling::*[self::purpose | self::scope | self::manstru]) + 1

    If these elements can occur at different levels (not as siblings),
    then it's a little more complicated. Hopefully, you won't have to
    worry about that, but if it ends up that you do, come on back and
    we'll take another crack at it.

    -Brandon 🙂


    On Wed, Oct 12, 2011 at 11:38 PM, Caroline Leccese
    <caroline@thecodesource.net> wrote:
    > Hi Brandon,
    >
    > Thanks for your reply. Going by the PDF I was given of finished output which
    > is my only reference, Foreword Title is labeled 10, List of Related
    > Publications Title is labeled 8 and Acronyms Title is labeled 9. Then
    > Purpose Title is labeled 1, Scope is 2 and Manual Structure is 3.
    >
    > If I make <forewordwp> a Division and <foreword> a Formal Block, Foreword
    > Title is labeled 4. If I make <foreword> a Division, it restarts at 1. No
    > matter how I've set up the rest of the elements, as either Formal Blocks or
    > Divisions, the title numbers are always 1 for everything below Foreword. So
    > I thought there might be an XPath override for the current level I could
    > enter in the Title Number dialog box that would grab the label # for Purpose
    > which I could +1 to get 2 for the Scope Title, and 3 for Manual Structure
    > and so on. I tried using the restart numbering option but was unsuccessful.
    >
    > Thanks for any help!
    >
    > Caroline
    >
    cleccese1-VisitorAuthor
    1-Visitor
    October 13, 2011

    Thank you again, Brandon. I tried both expressions in the override box:


    count(preceding-sibling::purpose | preceding-sibling::scope | preceding-sibling::manstru) + 1


    count(preceding-sibling::*[self::purpose | self::scope | self::manstru]) + 1


    but I'm still getting a 1 for the label numbers. Unless I misunderstood? Plus there are more sibling elements than these three so the expression would be unwieldy. I'm spending too much time on this, I might just hard-code the numbers as a last resort. I really appreciate all your help.

    1-Visitor
    October 13, 2011
    My bad (that's what I get for coding in email and not testing).  Try this:

    count(../preceding-sibling::*[self::purpose | self::scope | self::manstru]) + 1

    For something a little more generic that can handle the variety of
    possible siblings without getting really bulky:

    count(preceding-sibling::*[title]) + 1

    -Brandon 🙂


    On Thu, Oct 13, 2011 at 2:00 AM, Caroline Leccese
    <caroline@thecodesource.net> wrote:
    > Thank you again, Brandon. I tried both expressions in the override box:
    >
    > count(preceding-sibling::purpose | preceding-sibling::scope |
    > preceding-sibling::manstru) + 1
    >
    > count(preceding-sibling::*[self::purpose | self::scope | self::manstru]) + 1
    >
    > but I'm still getting a 1 for the label numbers. Unless I misunderstood?
    > Plus there are more sibling elements than these three so the expression
    > would be unwieldy. I'm spending too much time on this, I might just
    > hard-code the numbers as a last resort. I really appreciate all your help.
    >
    > ----------
    cleccese1-VisitorAuthor
    1-Visitor
    October 14, 2011

    Hi Brandon,


    Again, thank you so much!


    This kinda works:


    count(../preceding-sibling::*[title])


    I just have to tweak it for when there are other elements with titles between siblings.

    1-Visitor
    October 14, 2011
    Caroline,
    By that, do you mean, "...other elements... between siblings" that you don't want to number?

    Steve Thompson
    +1(316)977-0515
    cleccese1-VisitorAuthor
    1-Visitor
    October 14, 2011

    Hi Steve,


    Yes, there is an index with a title between two siblings, which threw off the numbering. So I adjusted the xpath expression to


    count(../preceding-sibling::*[title]) - 1


    for the elements after the index.


    And then for the first three elements which are numbered 10, 8 and 9 respectively in my PDF reference, I'm hoping I can cut and paste them to match their position in the PDF.)