cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Community Tip - Want the oppurtunity to discuss enhancements to PTC products? Join a working group! X

How to Capture Generated Section Number in Styler?

cleccese
6-Contributor

How to Capture Generated Section Number in Styler?

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 14

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


cleccese
6-Contributor
(To:cleccese)

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.

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-----
cleccese
6-Contributor
(To:cleccese)

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>

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
>
cleccese
6-Contributor
(To:cleccese)

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.

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.
>
> ----------
cleccese
6-Contributor
(To:cleccese)

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.

Caroline,
By that, do you mean, "...other elements... between siblings" that you don't want to number?

Steve Thompson
+1(316)977-0515
cleccese
6-Contributor
(To:cleccese)

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.)

If you make that:

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

then you don't have to do any other math, and it adapts to more situations for you.
My $.02,
Steve Thompson
+1(316)977-0515
cleccese
6-Contributor
(To:cleccese)

Hi Steve,


Thank you so much! But I am getting the same issue -- coverage is labeled 4 and locinfo is labeled 6. <indexscheme> is not showing up in my PDF so I don't know what it is or what I'm supposed to do with it. It has no content. Maybe I can delete it?


<coverage>
<title></title>
<para></para>
</coverage>
<indexscheme>
<title></title>
</indexscheme>
<locinfo>
<title></title>
<para></para>
</locinfo>

You didn't specify the name of your index element, so Steve had to
guess. Given that the actual name is "indexscheme", you'll need to
adjust Steve's version to:

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

I still think you'll need a "+ 1" on the end, but you should be able
to see pretty easily if that's the case. This translates, roughly, to
'go up to the parent (..) element of the title and count all of the
preceding sibling (please let me know if you're not sure what that
means) elements (* = element of any name) that are not "indexscheme"
elements and that have a "title" child element'. XPath lets you get
arbitrarily specific about what you want to count, so there's pretty
much no reason why you can't get a single expression that works for
all cases without having to artificially add a "- 1" or the like on
certain cases to accommodate one particular document.

If there are any other twists in this tale or details that you've
omitted, please fill us in, as the sooner you can give us a complete,
accurate and concrete description of the problem you're trying to
solve, the sooner we can give you a complete, working solution.

-Brandon 🙂


On Fri, Oct 14, 2011 at 2:27 PM, Caroline Leccese
<caroline@thecodesource.net> wrote:
> Hi Steve,
>
> Thank you so much! But I am getting the same issue -- coverage is labeled 4
> and locinfo is labeled 6. <indexscheme> is not showing up in my PDF so I
> don't know what it is or what I'm supposed to do with it. It has no content.
> Maybe I can delete it?
>
> <coverage>
> <title></title>
> <para></para>
> </coverage>
> <indexscheme>
> <title></title>
> </indexscheme>
> <locinfo>
> <title></title>
> <para></para>
> </locinfo>
>
> -----End Original Message-----
cleccese
6-Contributor
(To:cleccese)

Hi Brandon,


Thank you, that resolved it! I have zero experience with XPath and the lightbulb didn't go on regarding index/indexscheme until I had looked at the two XPATH expressions side by side.Your explanation was helpful. The XPATH syntax just wasn't clicking for me.


I am so grateful for everyone's help!


Announcements

Top Tags