set-attributes
The set-attributes
action is used to set attributes on DOM elements in the current fit://request/content
.
xpath="..."
or css-selector="..."
for selecting element nodes in the document (required).in="..."
to define the input location (optional, default is fit://request/content
).out="..."
to define the output location (optional, default is fit://request/content
).xpath
.The action reads the in
content, changes the document by setting attributes on the elements selected by the given xpath
or css-selector
, and writes the changed document to out
. Selected nodes that are not elements are ignored. All attributes specified on the set-attributes
element except the xpath
, css-selector
, in
and out
attributes are set on the selected elements, overriding already existing attributes.
Check the css selector documentation for more information regarding support und utilization.
<flow>
<!-- set ai-scaling-width="50%" on all img elements -->
<set-attributes xpath="//img" ai-scaling-width="50%"/>
<!-- set ai-quality="30" on all img elements with class="lowq" -->
<set-attributes xpath="//img[@class='lowq']" ai-quality="30"/>
<!-- set class="myClass" and dir="rtl" on the p element with id="foo" -->
<set-attributes xpath="//p[@id='foo']" class="myClass" dir="rtl"/>
<set-attributes css-selector="div#myID div.myClass" new-attribute="myNew" />
…
</flow>
Input:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src="...">
<p><img src="..." ai-scaling-width="75%"></p>
<img class="lowq" src="...">
<p id="foo"></p>
<div id="myID">
<div class="myClass">X</div>
<div class="notMyClass">Y</div>
</div>
<div id="notMyID">
<div class="myClass">X</div>
</div>
</body>
</html>
Output:
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<img src="..." ai-scaling-width="50%">
<p><img src="..." ai-scaling-width="50%"></p>
<img class="lowq" src="..." ai-scaling-width="50%" ai-quality="30">
<p id="foo" class="myClass" dir="rtl"></p>
<div id="myID">
<div class="myClass" new-attribute="myNew">X</div>
<div class="notMyClass">Y</div>
</div>
<div id="notMyID">
<div class="myClass">X</div>
</div>
</body>
</html>
The following errors are considered non-fatal. The flow will continue, no content will be written to out
.
xpath
nor a css-selector
attribute is specified.xpath
and css-selector
attributes are specified both.xpath
or css-selector
attribute contains an invalid expression.in
document is missing, empty or no DOM.