xsl-list
[Top] [All Lists]

Re: [xsl] Comparing before and after records [SEC=UNCLASSIFIED]

2008-07-07 21:50:33
Hi Jeff,

Thanks, worked beautifully!

best regards,

Enrico Raymundo



                                                                           
             Jeff Sese                                                     
             <jeferson(_dot_)sese(_at_)as                                       
      
             iatype.com>                                                To 
                                            
xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)co 
             08/07/2008 01:26               m                              
             PM                                                         cc 
                                                                           
                                                                   Subject 
             Please respond to              Re: [xsl] Comparing before and 
             xsl-list(_at_)lists(_dot_)mu              after records            
      
              lberrytech.com                [SEC=UNCLASSIFIED]             
                                                           Protective Mark 
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           



Please try this stylesheet, just wrap a xsl:result-document
instruction to the template for After to create separate XML files:

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
             <xsl:key name="Before_Events" match="Before" use="Event_Id"/>
             <xsl:template match="/">
                         <xsl:apply-templates select="Events/After"/>
             </xsl:template>
             <xsl:template match="/Events/After">
                         <Event>
                                     <xsl:choose>
                                                 <xsl:when
test="key('Before_Events', Event_Id)">

<Operation>MODIFY</Operation>
                                                             <xsl:comment
select="if (key('Before_Events', Event_Id)/
Event_Field != Event_Field) then 'Changed' else 'Unchanged'"></
xsl:comment>
                                                 </xsl:when>
                                                 <xsl:otherwise>

<Operation>CREATE</Operation>
                                                 </xsl:otherwise>
                                     </xsl:choose>
                                     <xsl:copy-of select="Event_Field"/>
                         </Event>
             </xsl:template>
</xsl:stylesheet>

Hope this helps,
-- Jeff

On 07 8, 08, at 7:15 AM, Enrico(_dot_)Raymund(_at_)immi(_dot_)gov(_dot_)au 
wrote:

Hi Greg,

Thanks.  Yeah, that's a typo there, but it definitely will not work
as it
needs to include the Event_Id of current context (After) and
corresponding
Before/Event_Id.

regards,

Enrico Raymundo




             "Greg Fausak"
             <lgfausak(_at_)gmail(_dot_)c

om>                                                        To
                                            xsl-
list(_at_)lists(_dot_)mulberrytech(_dot_)co
             08/07/2008 12:57               m

AM                                                         cc


Subject
             Please respond to              Re: [xsl] Comparing
before and
             xsl-list(_at_)lists(_dot_)mu              after records
              lberrytech.com                [SEC=UNCLASSIFIED]

Protective Mark










Hi,

I'm kinda new to the list and to xslt.  But, trying to understand
what you're doing here.

First, you reference:
---
                   <xsl:when test="//Before/Even_Field/text() =
Event_Field/text()">
                       <xsl:comment>unchanged</xsl:comment>
                   </xsl:when>
---

Probably just an example error, but, Event_Field instead of
Even_Field.

-g


On Mon, Jul 7, 2008 at 1:33 AM,  
<Enrico(_dot_)Raymund(_at_)immi(_dot_)gov(_dot_)au> wrote:
Hi Abel,

I was not able to come back to you sooner but here it is:

XML Input:
<?xml version="1.0" encoding="UTF-8"?>
<Events>
   <Before>
       <Event_Type>A</Event_Type>
       <Event_Field>1111</Event_Field>
       <Event_Id>1001</Event_Id>
   </Before>
   <Before>
       <Event_Type>B</Event_Type>
       <Event_Field>2222</Event_Field>
       <Event_Id>1002</Event_Id>
   </Before>
   <After>
       <Event_Type>A</Event_Type>
       <Event_Field>1111</Event_Field>
       <Event_Id>1001</Event_Id>
   </After>
   <After>
       <Event_Type>B</Event_Type>
       <Event_Field>2233</Event_Field>
       <Event_Id>1002</Event_Id>
   </After>
   <After>
       <Event_Type>C</Event_Type>
       <Event_Field>1122</Event_Field>
       <Event_Id>1003</Event_Id>
   </After>
</Events>

The XSL file:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
   <xsl:output encoding="UTF-8" indent="yes" method="xml"
version="1.0"/>
   <xsl:strip-space elements="*"/>
   <xsl:key match="/Events/Before" name="BEFORE_ID" use="Event_Id"/>
   <!-- Root Template -->
   <xsl:template match="/">
       <xsl:choose>
           <xsl:when test="count(//After) &gt; 0">
               <xsl:for-each select="//After">
                   <xsl:choose>
                       <xsl:when test="key('BEFORE_ID', Event_Id)">
                           <xsl:call-template
name="INSTANTIATE_MODIFY_EVENT">
                               <xsl:with-param name="EVENT_TYPE"
select="Event_Type"/>
                               <xsl:with-param name="AFTER_EVENT_ID"
select="Event_Id"/>
                           </xsl:call-template>
                       </xsl:when>
                       <xsl:otherwise>
                           <xsl:call-template
name="INSTANTIATE_CREATE_EVENT">
                               <xsl:with-param name="EVENT_TYPE"
select="Event_Type"/>
                               <xsl:with-param name="AFTER_EVENT_ID"
select="Event_Id"/>
                           </xsl:call-template>
                       </xsl:otherwise>
                   </xsl:choose>
               </xsl:for-each>
           </xsl:when>
           <xsl:otherwise>
               <!-- No occurence of 'After':  there is nothing to  >>
output>>> -->
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>
   <!-- >>
=============================================================-->
   <!-- NAMED  >> TEMPLATES
-->
   <!-- >>
=============================================================-->
   <xsl:template name="INSTANTIATE_MODIFY_EVENT">
       <!-- MODIFY -->
       <xsl:param name="EVENT_TYPE"/>
       <xsl:param name="AFTER_EVENT_ID"/>
       <xsl:result-document encoding="utf-8"
href="{$EVENT_TYPE}_{$AFTER_EVENT_ID}.xml"
           indent="yes" method="xml">
           <Event>
               <Operation>MODIFY</Operation>
               <xsl:choose>

                   <!-- ### THIS IS WHERE I NEED HELP ###-->
                   <!-- NEED TO TAKE INTO CONSIDERATION the  >> Event_Id
of>>> the current (After) context -->
                   <!-- CAN THIS BE DONE WITHOUT USING key() and>>>
generate-id()? -->
                   <xsl:when test="//Before/Even_Field/text() =
Event_Field/text()">
                       <xsl:comment>unchanged</xsl:comment>
                   </xsl:when>
                   <!-- ### THIS IS WHERE I NEED HELP ###-->

                   <xsl:otherwise>
                       <xsl:comment>changed</xsl:comment>
                   </xsl:otherwise>
               </xsl:choose>
               <Field>
                   <xsl:value-of select="Event_Field"/>
               </Field>
           </Event>
       </xsl:result-document>
       <!-- CREATE -->
   </xsl:template>

   <xsl:template name="INSTANTIATE_CREATE_EVENT">
       <xsl:param name="EVENT_TYPE"/>
       <xsl:param name="AFTER_EVENT_ID"/>
       <xsl:result-document encoding="utf-8"
href="{$EVENT_TYPE}_{$AFTER_EVENT_ID}.xml"
           indent="yes" method="xml">
           <Event>
               <Operation>CREATE</Operation>
               <Field>
                   <xsl:value-of select="Event_Field"/>
               </Field>
           </Event>
       </xsl:result-document>
   </xsl:template>
</xsl:stylesheet>

 The requirements are as follows:

(1) Create a separate XML file for each "After" instance.
(2) If an "After" instance has no corresponding "Before" instance,
related
by EventId, then this a create operation, ie,
<Operation>CREATE</Operation>
(3) If an  "After" instance has a corresponding "Before" instance,
related
by EventId, then this a modify operation, ie,
<Operation>MODIFY</Operation>
     (3.1) If the value of the Before/Event_Field != to
After/Event_Field,
put a comment:  "<!--changed-->"
     (3.2) If the value of the Before/Event_Field = to After/
Event_Field,
put a comment:  "<!--unchanged-->"

The code between "<!-- ### THIS IS WHERE I NEED HELP ###-->" is
where I
need a proper XPath put in.  With the input XML, the XSLT creates
3 XML
files -- which it does,  the XSLT created the following files:

A_1001.xml  [the comment is wrong (as the XPath is wrong):
Before/EventField = 1111; After/EventField = 1111 (unchanged)]

<?xml version="1.0" encoding="utf-8"?>
<Event>
   <Operation>MODIFY</Operation>
   <!--changed-->
   <Field>1111</Field>
</Event>


B_1002.xml [the comment field is correct:   Before/EventField = 2222;
After/EventField = 2233 (changed)]

<?xml version="1.0" encoding="utf-8"?>
<Event>
   <Operation>MODIFY</Operation>
   <!--changed-->
   <Field>2233</Field>
</Event>

C_1003.xml [This is correct because there is no <Before> for
EventId="1003"]

<?xml version="1.0" encoding="utf-8"?>
<Event>
   <Operation>CREATE</Operation>
   <Field>1122</Field>
</Event>

Thanks in advance.

Enrico





            Abel Braaksma
            <abel(_dot_)online(_at_)xs4a

ll.nl>                                                     To
                                           xsl-
list(_at_)lists(_dot_)mulberrytech(_dot_)co
            03/07/2008 05:22               m

PM                                                         cc


Subject
            Please respond to              Re: [xsl] Comparing
before
            xsl-list(_at_)lists(_dot_)mu              and after records
             lberrytech.com                [SEC=UNCLASSIFIED]

Protective Mark










Enrico(_dot_)Raymund(_at_)immi(_dot_)gov(_dot_)au wrote:

The creation of the multiple output document and the
transformations are
easy.  The help I need is in comparing the <Before> and <After>
contents
with the same <EventId>.

Your example input and output looks excellent and clearly
indented, but
please also show us your current xslt file, so we can help you with
where you went wrong (and explain what you tried so we can understand
where you're coming from). Now it's just a guessing game... (see the
list guidelines for more help).

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--------------------------------------------------------------------
Important Notice: If you have received this email by mistake, please
advise the sender and delete the message and attachments
immediately.  This
email, including attachments, may contain confidential, sensitive,
legally
privileged and/or copyright information.  Any review, retransmission,
dissemination or other use of this information by persons or
entities other
than the intended recipient is prohibited.  DIAC respects your
privacy and
has obligations under the Privacy Act 1988.  The official departmental
privacy policy can be viewed on the department's website at
www.immi.gov.au. See: http://www.immi.gov.au/functional/privacy.htm

---------------------------------------------------------------------


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--





--
Greg Fausak
greg(_at_)thursday(_dot_)com

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--






--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--




--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--