[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] Move elements to preceding parent


Subject: Re: [xsl] Move elements to preceding parent
From: "G. Ken Holman" <gkholman@xxxxxxxxxxxxxxxxxxxx>
Date: Thu, 18 Jun 2009 16:15:07 -0400

At 2009-06-18 21:15 +0300, you wrote:
I tried to test the stylesheet with non-<p> elements inside body and I
see they break the paragraph.

Indeed they do ... your original specification implied paragraphs were adjacent.


Input Example:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
<p dir="rtl">
<span class="chapter">line1</span>
</p>
<p dir="rtl"><span class="regular">line10</span>
<span class="regular">line11</span>
</p>
<p dir="rtl"><span class="regular">line12</span>
</p>
<p dir="rtl"><span class="regular">line13.</span>
</p>
<p dir="rtl"><span class="regular">line14</span>
</p>
<p dir="rtl"><span class="regular">line15</span>
</p>
<h5>
<img src="images/test.jpg" width="35.00" height="30.00" alt="images.jpg" />


</h5>
<p dir="rtl"><span class="regular">line16.</span>
</p>
<p dir="rtl"><span class="regular">line17"</span>
</p>

</body>
</html>

Output:
<?xml version="1.0" encoding="UTF-8"?><html
xmlns="http://www.w3.org/1999/xhtml">
   <body>
      <p dir="rtl">
         <span class="chapter">line1</span>

      </p>
      <p dir="rtl"><span class="regular">line10</span>
         <span class="regular">line11</span>
         <span class="regular">line12</span>
         <span class="regular">line13.</span>

      </p>
      <p dir="rtl"><span class="regular">line14</span>

      </p>
      <p dir="rtl"><span class="regular">line15</span>

      </p>
      <h5>
         <img src="images/test.jpg" width="35.00" height="30.00"
alt="images.jpg" />


</h5> <p dir="rtl"><span class="regular">line16.</span>

      </p>
      <p dir="rtl"><span class="regular">line17"</span>

      </p>
   </body>
</html>

I thought the <h5> element should be grouped as a seperate group
because of the condition group-ending-with="*[not(self::p)] ...

No, because group-ending-with= and group-starting-with= work on consecutive members of the population.


What should I change so the output will be:
<?xml version="1.0" encoding="UTF-8"?><html
xmlns="http://www.w3.org/1999/xhtml">
   <body>
      <p dir="rtl">
         <span class="chapter">line1</span>

      </p>
      <p dir="rtl"><span class="regular">line10</span>
         <span class="regular">line11</span>
         <span class="regular">line12</span>
         <span class="regular">line13.</span>

      </p>
      <p dir="rtl"><span class="regular">line14</span>

                <span class="regular">line15</span>
                <span class="regular">line16.</span>
      </p>
      <h5>
         <img src="images/test.jpg" width="35.00" height="30.00"
alt="images.jpg" />


</h5>


<p dir="rtl"><span class="regular">line17"</span>

      </p>
   </body>
</html>

I wouldn't want to try until I better understood the specification. Your need now breaks my top-down perspective of the content. Up until now all output information was in input order, and you are now asking for an arbitrary re-ordering of non-<p> elements with the <p> elements. Your image is being moved after "line 16" rather than the original order of being after "line 15".


Perhaps Martin can exploit his axis-based approach to meet this new requirement.

Nothing comes immediately to mind for my approach within the bounds of a voluntary effort. I'll post something if I think of it.

Meanwhile, if you can provide more detail about your complete needs, that will help everyone interested in assisting you.

. . . . . . . . . . . Ken

--
Crane Softwrights Ltd.          http://www.CraneSoftwrights.com/m/
Training tools: Comprehensive interactive XSLT/XPath 1.0/2.0 video
Video lesson:    http://www.youtube.com/watch?v=PrNjJCh7Ppg&fmt=18
Video overview:  http://www.youtube.com/watch?v=VTiodiij6gE&fmt=18
G. Ken Holman                 mailto:gkholman@xxxxxxxxxxxxxxxxxxxx
Male Cancer Awareness Nov'07  http://www.CraneSoftwrights.com/m/bc
Legal business disclaimers:  http://www.CraneSoftwrights.com/legal


Current Thread
Keywords