Level-2 / Transphporm

Transformation Style Sheets - Revolutionising PHP templating
276 stars 27 forks source link

#name:attr():data[var="val"] {} fails #230

Open cj-clx opened 4 years ago

cj-clx commented 4 years ago

Somewhere between the 1.4 release from last November and the current head of dev-master, this stopped working:

<?php
require "vendor/autoload.php";

$tss = <<<TSS
#list-claims-form:attr(action):data[input.alternate!="alternate"] {
    content: "/list-claims";
}
#list-claims-form:attr(action):data[input.alternate="alternate"] {
    content: "/list-claims/alternate";
}
TSS;

$xml = '<form id="list-claims-form" action="FOOBAR">';

$data = [];
$data["input"] = [];

$template = new Transphporm\Builder($xml, $tss);
$output = $template->output($data)->body;
echo $output . PHP_EOL;

Expected output:

<form id="list-claims-form" action="/list-claims"></form>

Actual output:

<form id="list-claims-form" action="/list-claims/alternate"></form>
cj-clx commented 4 years ago

Note 1

Strangely, this does work:

<?php
require "vendor/autoload.php";

$tss = <<<TSS
#list-claims-form:attr(action):data[input.alternate!="alternate"] {
    content: "/list-claims";
}
/*
#list-claims-form:attr(action):data[input.alternate="alternate"] {
    content: "/list-claims/alternate";
}
*/
#list-claims-form:data[input.alternate="alternate"]:attr(action) {
    content: "/list-claims/alternate";
}
TSS;

$xml = '<form id="list-claims-form" action="FOOBAR">';

$data = [];
$data["input"] = [];

$template = new Transphporm\Builder($xml, $tss);
$output = $template->output($data)->body;
echo $output . PHP_EOL;

That is, the difference is this (in the false side of the branch):

#list-claims-form:attr(action):data[input.alternate="alternate"] { }

Versus this:

#list-claims-form:data[input.alternate="alternate"]:attr(action) { }
cj-clx commented 4 years ago

Is the failing syntax perhaps just plain wrong? Does the attr() specifier have to come after the data[] specifier all the time, perhaps?