]> git.sesse.net Git - xml-template/commitdiff
Add alternate() to the PHP version, which should now be rather feature-complete.
authorsgunderson@bigfoot.com <>
Sat, 12 Aug 2006 14:04:05 +0000 (16:04 +0200)
committersgunderson@bigfoot.com <>
Sat, 12 Aug 2006 14:04:05 +0000 (16:04 +0200)
attribute2.php [new file with mode: 0644]
xml-template.php

diff --git a/attribute2.php b/attribute2.php
new file mode 100644 (file)
index 0000000..6beb24b
--- /dev/null
@@ -0,0 +1,14 @@
+<?php
+require('xml-template.php');
+
+$doc = XML_Template_process_file('clone.xml', array(
+       'color' => 'blue',
+       '#things' => XML_Template_alternate('li.class', array(
+               array( 'li' => 'Raindrops on roses' ),
+               array( 'li' => 'Whiskers on kittens' ),
+               array( 'li' => 'Bright copper kettles' ),
+               array( 'li' => 'Warm, woolen mittens' ),
+       ), array('odd', 'even'))
+));
+print $doc->dump_mem();
+?>
index 48837c7264eb01ace3c27dbfea17fe5cce46de21..dc84bf6e5f8ba023977b997397d3036a9129968f 100644 (file)
@@ -124,6 +124,19 @@ function XML_Template_clean($node)
        }
 }
 
+# FIXME: use varargs here
+function XML_Template_alternate($tag, $array, $elems)
+{
+       $i = 0;
+       $num = count($elems);
+
+       for ($i = 0; $i < count($array); $i++) {
+               $array[$i][$tag] = $elems[$i % $num];
+       }
+
+       return $array;
+}
+
 function is_associative_array($arr)
 {
        if (!is_array($arr)) {