domiterator

BacksetAttribute("href",$_SERVER["HTTP_REFERER"]);>
  • domiterator Since AWS XMS 1.0 beta 10
    • eachreference ($el,$label,$value,$recordset) Since AWS XMS 1.0 beta 10
    • eachnamedreference ($el,$label,$value,$recordset) Since AWS XMS 1.0 rc2
    • norecords Since AWS XMS 1.0 RC1

  • Download exampleRun example
    Replaces with a given value, corresponding descendants of unit indicated by the labels of the array;
    Filter function needs to return an array of associative arrays; the labels of these assoc arrays will be used as values of attribute reference of those descandants of unit we need to change;

    Context: //app/filters/dom/filter/domiterator

    When: for database operations mainly;

    Tips:
    - Use PDO Abstraction layer or PEAR/MDB2, to retreive data from your database; This way you will be able to get all data very easy and use it in this directive; $db = new PDO(DSN, USER, PASS);
    return $db->query("SELECT `location` from warehouse where id='".$_POST["id"]."';")->fetchAll(PDO::FETCH_ASSOC);


    Remarks:
    - This directive uses DOM to make replacements
    - By default, domiterator will replace the content of each reference descendant of "unit"; if we only need to change an attribute for a reference (or we have another reference inside and don't want to loose it) we have to set skip attribute for that reference; if instead of replacing the content of a reference we have to append/prepend the value, we need to set skip attribute as well as modtype attribute (modtype values are: append, prepend or replace)

    -unit is a descendant node of the each xpath node, that will be multiplied; unit node will be removed from DOM;unit node will be identified by the document processor as the one child having the unit attribute;

    - corresponding descendants of unit will be identified by document processor by the value of "reference" attribute; this attribute needs to be one of the labels of the array bellow;

    -filter node first processing instruction holds the function code; this has to return an array of associatice arrays like:
    array(
    0=>array(name => "john", location=>"My City",product=> "My Product"),
    1=>array(name => "Max", location=>"His City",product=> "His Product"))


    -domiterator node text content holds xpath;

    -eachreference child node is optional; Since the directive will only replace the content of the corresponding node, in case you need to change any of the reference's attributes you can use eachnode; Document processor will build a function from the text content of eachreference; This function will be executed for all references and called with following parameters: $el - corresponding descendant, $label - label of the array, $value - value of the array[$label], $recordset entire database recordset (row) as retrieved (like: array(name => "john", location=>"My City",product=> "My Product") /as per above)

    -eachnamedreference/referencename child node is optional; This function will be called for those references only that have the value of "reference" attribute identical to the name of this node (these are also known as "named references").
    Ex: for the array model above, you can create eachnamedreference/name or eachnamedreference/location or eachnamedreference/product

    See also:

    Array type in php

    Setting up filter callback function
    Setting up the directive xpath
    Setting up the eachreference directive (optional)
    Setting up the eachnamedreference directive (optional)
    Setting up the document entities
    Run exampleDownload example