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

The community will undergo maintenance on October 16th at 10:00 PM PDT and will be unavailable for up to one hour.

XPATH question (again)

cleccese
6-Contributor

XPATH question (again)

Here's my structure (Styler 5.4):


<condtinsp>
<inspection>
<condition></condition>
<req></req>
</inspection><inspection>
<condition></condition>
<req></req>
</inspection><inspection>
<condition></condition>
<req></req>
</inspection><inspection>
<condition></condition>
</condtinsp>


I want to number the condition tags but only if they have content (they have no title so making them a Formal Block didn't help) with the XPATH count(../preceding::condition) + 1


I created a content test condition for the XPATH on <condition> in Styler so only the non-empty conditions are numbered, but the counter is incrementing on the empty conditions. So the first three numbered <condition>s are numbered 1, 9, 10 because there are 8 empty conditions following the first numbered one.


I don't know how to keep the empty <conditions> from incrementing the counter, or if that is even possible. Some kind of subtraction, maybe?


Thanks for any ideas!

5 REPLIES 5

Using FOSI terminology, this might work:

You could put a savetext with a conrule (construction rule) of #CONTENT in the e-i-c (element-in-context) for <condition>.

Then you could have an attribute rule to check if this savetext had a value of #ANY and then increment the counter.

Assuming that your structure is consistent and the <condition> element is always a child of <inspection>, you would need to reset this savetext to be equal to "\\" (null or empty in FOSI talk) in the e-i-c for <inspection>.



Hi Caroline--



You probably want something like this:



count(../preceding-sibling::condition[not(* | text())])+ 1



HTH.



--Clay



Clay Helberg

Senior Consultant

TerraXML


Your XPath counts all preceding conditions, but you only want to count the
ones that have a child node, so try something like
"count(preceding::condition[node()]) + 1". If you have "empty" conditions
that get counted because of some whitespace inside of them, try
"count(preceding::condition[* or normalize-space(.)]) + 1".

-Brandon 🙂


On Thu, May 17, 2012 at 3:35 AM, Caroline Leccese <
caroline@thecodesource.net> wrote:

> Here's my structure (Styler 5.4):
>
> <condtinsp>
> <inspection>
> <condition></condition>
> <req></req>
> </inspection><inspection>
> <condition></condition>
> <req></req>
> </inspection><inspection>
> <condition></condition>
> <req></req>
> </inspection><inspection>
> <condition></condition>
> </condtinsp>
>
> I want to number the condition tags but only if they have content (they
> have no title so making them a Formal Block didn't help) with the XPATH
> count(../preceding::condition) + 1
>
> I created a content test condition for the XPATH on <condition> in Styler
> so only the non-empty conditions are numbered, but the counter is
> incrementing on the empty conditions. So the first three numbered
> <condition>s are numbered 1, 9, 10 because there are 8 empty conditions
> following the first numbered one.
>
> I don't know how to keep the empty <conditions> from incrementing the
> counter, or if that is even possible. Some kind of subtraction, maybe?
>
> Thanks for any ideas!
>

Oops, I got it backward, that one will count only the conditions you
*don't* want. Here's the right version:



count(../preceding-sibling::condition[boolean(* | text())])+ 1





Clay Helberg

Senior Consultant

TerraXML


cleccese
6-Contributor
(To:cleccese)

Thank you everyone! Brandon's worked.


Although this morning I realized I could simply increment and output a counter in FOSI in the non-empty content condition I had set up for <condition> in Styler:


<enumerat increm="1" enumid="conditionct"/">
<usetext source="conditionct,\.\,@10pt" placemnt="before"></usetext>


I should have figured this out before posting but I do keep all the responses to my XPATH questions in a file which I refer back to constantly, so I appreciate everyone's help.


Whoops! <condition> has to reset when it hits<syshd>


<inspection>
<condition></condition>
<req></req>
</inspection>
<inspection>
<condition></condition>
<req></req>
</inspection>
<inspection>
<condition></condition>
<req></req>
</inspection>


<syshd></syshd>


<inspection>
<condition></condition>
<req></req>
</inspection>
<syshd></syshd>
<inspection>
<condition></condition>
<req></req>
</inspection>


Thanks to Brandon's response to another thread, I figured it out to be:


count(preceding::condition[node()]) - count(preceding::syshd[1]/preceding::condition[node()]) + 1

Announcements

Top Tags