xsl-list
[Top] [All Lists]

Re: Re: Sorting and Merge

2003-11-18 11:35:37
Thanks for this new approach. We tried it and it is
easier than we thought.

Dongling


--- Dimitre Novatchev <dnovatchev(_at_)yahoo(_dot_)com> wrote:
We have a member structure and allow users to
define
filters based on it. We can generate the result
after
applying those filters. But the problem is that
result
is messed up since the filter was applied
sequentially.

[snip]

After those filters are applied sequentially, we
got
the following result, but it contains duplicated
members and order of members is not the same as
original one.

[snip]

But we need
to go down each level and figure out the
position(recursive)and get rid of duplicate
members.
This transformation seems doing merge and sorting.
Please help me on this!

This can be done much easier if you transform the
original document and use
the "messed" result of the searches as criteria
which nodes from the
original document should be copied.

Something like this:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

 <xsl:output omit-xml-declaration="yes"
indent="yes"/>
 <xsl:strip-space elements="*"/>

  <xsl:template match="doc/MemberList">
    <MemberList>
      <xsl:apply-templates/>
    </MemberList>
  </xsl:template>

  <xsl:template match="Member[ancestor::doc]">
    <xsl:if test="/*/results/descendant::Member
                            [(_at_)name =
current()/@name]">
      <xsl:copy>
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
      </xsl:copy>
    </xsl:if>
  </xsl:template>
</xsl:stylesheet>

When the above transformation is performed on this
source.xml (the original
xml document appended with the search results):

<search>
  <doc>
    <MemberList>
      <Member name="P1">
        <Member name="P11">
          <Member name="P111"/>
        </Member>
        <Member name="P12">
          <Member name="P121"/>
        </Member>
      </Member>
      <Member name="P2">
        <Member name="P21"/>
        <Member name="P22"/>
      </Member>
    </MemberList>
  </doc>
  <results>
    <MemberList>
      <Member name="P1">
        <Member name="P12">
          <Member name="P121"/>
        </Member>
      </Member>
      <Member name="P2">
        <Member name="P21"/>
        <Member name="P22"/>
      </Member>
      <Member name="P1">
        <Member name="P11"/>
        <Member name="P12"/>
      </Member>
    </MemberList>
  </results>
</search>

the wanted result is produced:

<MemberList>
   <Member name="P1">
      <Member name="P11"/>
      <Member name="P12">
         <Member name="P121"/>
      </Member>
   </Member>
   <Member name="P2">
      <Member name="P21"/>
      <Member name="P22"/>
   </Member>
</MemberList>


Hope this helped!


=====
Cheers,

Dimitre Novatchev.
http://fxsl.sourceforge.net/ -- the home of FXSL



"Dongling Ding" <dling61(_at_)yahoo(_dot_)com> wrote in message

news:20031117194453(_dot_)92821(_dot_)qmail(_at_)web13902(_dot_)mail(_dot_)yahoo(_dot_)com(_dot_)(_dot_)(_dot_)
Thank Dimitre,

Let me give a clearer description of the problem.

We have a member structure and allow users to
define
filters based on it. We can generate the result
after
applying those filters. But the problem is that
result
is messed up since the filter was applied
sequentially.


Here is an example of the original member
structure.
The actual structure can be very deep in terms of
hierarchy.


<MemberList>
    <Member name="P1">
<Member name="P11">
<Member name="P111"/>
</Member>
<Member name="P12">
<Member name="P121"/>
</Member>
    </Member>
    <Member name="P2">
<Member name="P21"/>
                <Member name="P22"/>
    </Member>
</MemberList>

Here there are three filers created by user:

1. select the member name "P121" and its
ancestors.
They are P121, P12, and P1.
2. select the member name "P2" and its children.
They
are P2, P21, and P22.
2. select the member name "P1" and its children.
So,
P1, P11, and P21,

After those filters are applied sequentially, we
got
the following result, but it contains duplicated
members and order of members is not the same as
original one.

<MemberList>
<Member name="P1">
<Member name="P12">
<Member name="P121"/>
</Member>
</Member>
<Member name="P2">
<Member name="P21"/>
                <Member name="P22"/>
</Member>
<Member name="P1">
<Member name="P11"/>
<Member name="P12"/>
</Member>
</MemberList>

Therefore, the transformation requirement is to
merge
and reorder the above result based on the original
member structure. Dimitre suggested earlier to add
one

=== message truncated ===


__________________________________
Do you Yahoo!?
Protect your identity with Yahoo! Mail AddressGuard
http://antispam.yahoo.com/whatsnewfree

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



<Prev in Thread] Current Thread [Next in Thread>