[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Calculating Step Numbers Within and Following XML "IF"

Subject: Calculating Step Numbers Within and Following XML "IF" Statements
From: "Sam Byland" <shbyland@xxxxxxxxxxx>
Date: Sun, 16 May 2004 22:12:19 -0400
xml if
Hello all,

I've got a numbering puzzle that I hope someone will be able to solve.  The
kind of documents that I am working with are described in an earlier post
regarding the output of flowcharts (which I will post a reply to before too
much longer) (ref
http://www.biglist.com/lists/xsl-list/archives/200403/msg00222.html).  This
issue has to do with assigning "step numbers" in the output files of these
procedures.  Here's a typical (but simplified) structure of a source file:

<instruction>
    <step>
       ..  [should be step 1 in output]
        <step>
            ... [should be step 1.1 in output]
        </step>
    </step>
    <step/> ...[should be step 2 in output, etc]
    <step>
        <if>
            ...
            <step>
                <step>
                ...
                </step>
            </step>
            <elseif>
                <step>
                    ..
                </step>
                <step>
                    ..
                </step>
            </elseif>
            <else>
                <step/>
            </else>
        </if>
        <step>
            ...
        </step>
        ..
    </step>
    <step/>
</instruction>

The <if> elements are "resolved" at publish-time and determine which steps
end up in the output.  I'm using a two-phase transformation, and I assign
step numbers _after_ the "if statements" are resolved  ...  so far so good.

Now, we've been asked to provide the capability to output documents where
the "if statements" are _not_ resolved (this is to enable procedure review
by those not familiar with XML), so now when this "generic" output is
selected, the stylesheets output some text describing the "if" statement
(like "#IF blah" ... "#ELSE" ... "#ENDIF") and output _all_ step content.
The tricky part is assignment of step numbers within the IF statements, and
for steps following IF statements.  We've decided the step number following
any IF statement should be "one more" than the maximum step number that
could result from resolving the IF statement.  So, for example, the desired
step numbering I would need from the above example structure would be:

1
1.1
2
3
IF blah
3.1
3.1.1
ELSEIF blah
3.1
3.2
ELSE
3.1
ENDIF
3.3
   ^ since the "max" step number within the IF statement is the ELSEIF with
3.2, this one should be 3.3, and other branches in the IF, such as ELSEIF
and ELSE need to "restart" numbering back at 3.1...
4

To make things more interesting :), the IF structuring is quite flexible
when it comes to nesting:  <if>'s are allowable children of <if>, <elseif>,
and <else>, and there's no limit to the number of <elseif> children of <if>
(only one <else> child of course).  There's no limit on nesting of <step>
elements.

I'm posting to see if someone can come up with a clever "general"
solution -- the only way I've been able to get anywhere is by making
specific assumptions on nesting limits etc (this is acceptable as a
fall-back, but not preferred :)

thanx,

...sam

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.