Link to home
Start Free TrialLog in
Avatar of rshk2001
rshk2001

asked on

Section nesting

All:

How do you I transform below through xsl:
Input
<?xml version='1.0' encoding='utf-8'?>
<book>
      <section order="1"><p>Section 1: para</p></section>      
            <section order="1">
                 <p>Section 1: para</p>
                  <section order="2">
                        <p>Section 2: para</p>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                  </section>
            </section>
      
      <section order="1">
      <p>Section 1: para</p>
            <section order="2"><p>Section 2: para</p></section>
      </section>
      <dont>
            <section order="1">
                  <p>not to touch</p>
            </section>
      </dont>
      
</book>

output:

<?xml version='1.0' encoding='utf-8'?>
<book>
      <section order="1"><p>Section 1: para</p></section>      
            <section order="1">
                 <p>Section 1: para</p>
                  <section order="2">
                        <p>Section 2: para</p>
                              <section order="3">
                                    <section order="4">
                                          <p>Section 4: para</p>
                                    </section>
                              </section>
                  </section>
            </section>
      
      <section order="1">
      <p>Section 1: para</p>
            <section order="2"><p>Section 2: para</p></section>
      </section>
      <dont>
            <section order="1">
                  <p>not to touch</p>
            </section>
      </dont>
      
</book>

But when I try with node position it always returns a different one. Pl advise. Moreover, order values goes upto "n" values of depth.

Thanks
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Can you be more explicit about what exactly you want to happen.
I see that you added a section3, but what is the logic behind it?
I would like to help but have no clue where the question is
Avatar of rshk2001
rshk2001

ASKER

Gertone:

I am looking for grouping of sections based on the attribute value. Eg: The place where I added <section order="3"> is an hierarchy/depth of section level. Basically the order follows as: level 1, level 2, level 3..., when level 4 follows immediately after level 2 (ie <section order="2">) then a third order level is introduced before level 4 and that explains the above structure.

Thanks
OK, I see, can you use XSLT2, or should this be done using XSLT1?
xslt1
OK, I need more insight in the restrictions then.
Can I have a section 6 in a section 3, so that I have to add 4 AND 5?
and what is the logic with the P?µ
All P before the first section inside a section are left outside the grouping section,
or do you just need a wrapper around the subsection itself?

How do you deal with this?
  <section order="2">
                        <p>Section 2: para</p>
                        <p>Section 2: para</p>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                  </section>

and can this happen?
<section order="2">
                        <p>Section 2: para</p>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                        <p>Section 2: para</p>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                         <p>Section 2: para</p>
                 </section>
and if so, how do you want to deal with it?

I must say that based on your extreme flood of communication,
this is more an analysis task than a development task :-)
Gertone: Pl find below

  <section order="2">
                        <p>Section 2: para</p>
                        <p>Section 2: para</p>
<section order="3">

                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
</section>
                  </section>

>> and can this happen? - Yes and below is the tagging structure
<section order="2">
                        <p>Section 2: para</p>
            <section order="3">
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
</section>
                        <p>Section 2: para</p>
<section order="3">
                              <section order="4">
                                    <p>Section 4: para</p>
                              </section>
</section>
                         <p>Section 2: para</p>
                 </section>

Yes, if level 6 occurs then level 5 and level 4 must wrap before level 6.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial