mgaerber / basePIM-LEGACY

XML based Product Information Management
4 stars 0 forks source link

Mark changed nodes in Snapshotted Nodes #42

Closed micheee closed 12 years ago

micheee commented 12 years ago

(
let $live := <nodes>
    <node id="moto1" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
    <node id="moto55" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
    <node id="moto2" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>

    <node id="moto8" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>    
    <node id="moto101" ts="6">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
</nodes>

let $new :=<nodes>
    <node id="moto1" ts="4">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
    <node id="moto55" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
    <node id="moto2" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>    
    <node id="moto8" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
        <node id="moto7" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>    
    <node id="moto101" ts="2">
        <property name="bezeichnung">
            <value>
                <slot lang="de en" brand="any">Motor 1.6</slot> 
                <slot lang="fr" brand="citroen">Moteur 1.6</slot>
            </value>
        </property>
    </node>
</nodes>

let $liveMap := map:new(
    for $node in $live/node
    return map:entry($node/@id, $node/@ts)
    )
    return
    for $id in map:keys($liveMap)
    let $deleted := not($new/node[@id = $id])
    let $updated := $new/node[@id = $id] and $new/node[@id = $id]/@ts < $live/node[@id = $id]/@ts
    return <diff>
        { attribute {"deleted"} {$deleted} }
        { attribute {"updated"} {$updated} }
        { $live/node[@id = $id]}    
    </diff> )[@deleted = fn:true() or @updated = fn:true()]
micheee commented 12 years ago

above query does not yet mark nodes that have been deleted in live and are still present in snapshot.