2017 © Pedro Peláez
 

library querypath-repeat

QueryPath extension that adds extra methods for repeating selected elements

image

noi/querypath-repeat

QueryPath extension that adds extra methods for repeating selected elements

  • Friday, October 11, 2013
  • by noisan
  • Repository
  • 1 Watchers
  • 0 Stars
  • 10 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

QueryPath RepeatExtension

RepeatExtension is a QueryPath extension that adds the following methods:, (*1)

  1. repeat($counter [, $callback])
  2. repeatInner($counter [, $callback])

Installation

With Composer, run:, (*2)

$ php composer.phar require noi/querypath-repeat "*"

Alternatively, you can edit your composer.json manually and add the following:, (*3)

{
    "require": {
        "noi/querypath-repeat": "*"
    }
}

Usage

repeat()

\QueryPath\DOMQuery repeat(int|array|\Traversable $counter [, callable $callback ])

A quick example:, (*4)

<root><item>Test</item></root>');
$qp->find('item')->repeat(5);
$qp->writeXML();

OUTPUT:, (*5)

<?xml version="1.0"?>
<root>
  <item>Test</item>
  <item>Test</item>
  <item>Test</item>
  <item>Test</item>
  <item>Test</item>
</root>

And here is an example with a callback function:, (*6)

<root><number>Test</number><name>Test</name></root>');

$qp->find('number')->repeat(3, function ($i, $node) {
    qp($node)->append(':' . $i);
});

$names = array('Apple', 'Orange', 'Lemon');
$qp->find('name')->repeat($names, function ($name, $node) {
    qp($node)->text(strtoupper($name));
});

$qp->writeXML();

OUTPUT:, (*7)

<?xml version="1.0"?>
<root>
  <number>Test:0</number>
  <number>Test:1</number>
  <number>Test:2</number>
  <name>APPLE</name>
  <name>ORANGE</name>
  <name>LEMON</name>
</root>

repeatInner()

\QueryPath\DOMQuery repeatInner(int|array|\Traversable $counter [, callable $callback ])

A quick example:, (*8)

<root>

Test
Child AChild B
</root>'); $qp->find('div')->repeatInner(3); $qp->writeXML();

OUTPUT:, (*9)

<?xml version="1.0"?>
<root>
  <div>TestTestTest</div>
  <div>
    <span>Child A</span>
    <b>Child B</b>
    <span>Child A</span>
    <b>Child B</b>
    <span>Child A</span>
    <b>Child B</b>
  </div>
</root>

And here is an example with a callback function:, (*10)

<root><number>Test</number><items><name/></items></root>');

$qp->find('number')->repeatInner(3, function ($i, $node) {
    qp($node)->text($i);
});

$names = array('Apple', 'Orange', 'Lemon');
$qp->find('items')->repeatInner($names, function ($name, $node) {
    qp($node)->find('name')->text(strtoupper($name));
});

$qp->writeXML();

OUTPUT:, (*11)

<?xml version="1.0"?>
<root>
  <number>012</number>
  <items>
    <name>APPLE</name>
    <name>ORANGE</name>
    <name>LEMON</name>
  </items>
</root>

License

RepeatExtension is licensed under the MIT License - see the LICENSE file for details., (*12)

The Versions

11/10 2013

dev-master

9999999-dev

QueryPath extension that adds extra methods for repeating selected elements

  Sources   Download

MIT

The Requires

 

by Akihiro Yamanoi

extension xml jquery html xhtml repeat querypath

10/10 2013

v1.0

1.0.0.0

QueryPath extension that adds extra methods for repeating selected elements

  Sources   Download

MIT

The Requires

 

by Akihiro Yamanoi

extension xml jquery html xhtml repeat querypath