Jump to content
Sign in to follow this  
Justin Diana

Multi-pass Transformation

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:

<myXML>
  <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>
  <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>
  <page id=2>
    ... (same as above)
  </page>
</myXML>

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:

<myXML>
  <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>
</myXML>

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.

Thanks!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...