Jump to content

Multi-pass Transformation

Justin Diana

Recommended Posts

Hey all,

I'm fairly new to "advanced" XSLT development and, of course, my current task requires just that.

I have a source XML file that looks similar to:

  <page id=1>
    <text top="504" left="75">output value</text>
    <text top="106" left="25">output value</text>
    <text top="504" left="25">output value</text>
    <text top="106" left="18">output value</text>
    <text top="325" left="32">output value</text>
    <text top="70" left="5">output value</text>
  <page id=3>
    <text top="601" left="85">output value</text>
    <text top="344" left="15">output value</text>
    <text top="243" left="15">output value</text>
    <text top="243" left="48">output value</text>
    <text top="325" left="37">output value</text>
    <text top="70" left="15">output value</text>
  <page id=2>
    ... (same as above)

Basically, I want to rewrite it so that it's flattened out (make the page ID an attribute of the child text elements) and then sort the entire list by page first (so all the page 1s are together, page 2s are together, etc.), then sort WITHIN the page by top value (descending) and then left value (descending).

So it ends up looking something like:

  <text page="1" top="504" left="75">output value</text>
  <text page="1" top="504" left="25">output value</text>
  <text page="1" top="325" left="32">output value</text>
  <text page="1" top="106" left="25">output value</text>
  <text page="1" top="106" left="18">output value</text>
  <text page="1" top="70" left="5">output value</text>

  <text page="2" top="900" left="85">output value</text>
  <text page="2" top="564" left="15">output value</text>
  <text page="2" top="564" left="8">output value</text>
  <text page="2" top="223" left="48">output value</text>
  <text page="2" top="154" left="37">output value</text>
  <text page="2" top="11" left="15">output value</text>
  <text page="3" top="601" left="85">output value</text>
  <text page="3" top="344" left="15">output value</text>
  <text page="3" top="325" left="37">output value</text>
  <text page="3" top="243" left="15">output value</text>
  <text page="3" top="243" left="48">output value</text>
  <text page="3" top="70" left="15">output value</text>

I can get it to insert the page number as an attribute correctly, but I can't get it to THEN sort using that attribute as part of the sort criteria.  I can also get it to sort based on the top attribute, but it doesn't seem to do the secondary sort by left.

Any help would be much appreciated.


Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...