BlueM / XMLTransformer

Transforms XML (into XML, HTML, plaintext, …) using native PHP
9 stars 1 forks source link

any attribute wilcards? #5

Closed cigzigwon closed 9 years ago

cigzigwon commented 9 years ago

I don't see any usage for something like @* OR @name:* which wouldbe very handy for mass removal of unwanted attrs.

BlueM commented 9 years ago

There is no way to do this directly in XMLTransformer. But with version 1.1 (tagged a few minutes ago, which means it will be available via Composer shortly), the callback can take the arguments by reference – as usual, by prefixing the argument with an ampersand. (Exception: this won’t work with PHP 5.3.)

Example callback function:

function callback($elementName, &$attributes, $elementType)
{
    $attributes = []; // <-- This will clear all attributes
    return [
        '@title' => 'You can still set attributes like this',
    ];
}

Likewise, any other kind of filtering or removal can be accomplished using plain PHP.

cigzigwon commented 9 years ago

sweet man ur awesome! this really works great for me and just started using it.

On Wed, Aug 19, 2015 at 4:46 PM, Carsten Blüm notifications@github.com wrote:

There is no way to do this directly in XMLTransformer. But with version 1.1 (tagged a few minutes ago, which means it will be available via Composer shortly), the callback can take the arguments by reference – as usual, by prefixing the argument with an ampersand. (Exception: this won’t work with PHP 5.3.)

Example callback function:

function callback($elementName, &$attributes, $elementType){ $attributes = []; // <-- This will clear all attributes return [ '@title' => 'You can still set attributes like this', ];}

Likewise, any other kind of filtering or removal can be accomplished using plain PHP.

— Reply to this email directly or view it on GitHub https://github.com/BlueM/XMLTransformer/issues/5#issuecomment-132778742.