# Transform ❺🧪

Note that dynamic attributes would likely be moved here;

x-attribute is a transform / overwrite&#x20;

xe-element type?&#x20;

xx-element = change element type?&#x20;

ww-wrap = create element wrapper?&#x20;

## Use cases

* Modify attributes such as hrefs by combining static and dynamic CMS content
* Solve the lack of CMS attribute binding on ECommerce lists&#x20;
* Wrap collection lists / nested collection lists in a link by transforming a wrapper DIV

## Concept

* Sequential series of transforms, applied in order, e.g.
  * Create element
  * Add attribute
  * Add second attribute

## Example

Position within a collection list item, to target relative items such as a wrapper link.

Here we're using closest with a CSS selector;&#x20;

```html
<script type="sa5:transform:hson">
[]
selector: div.foo
target: closest
transform: elem
type: a
[]
// replace attribute
selector: a
target: closest
transform: attr
name: href
val: /browse?category=EMBED-FIELD
[]
</script>
```

```html
<script type="sa5:transform:attr"
   target="closest"
   selector="'a'"
   attr="href"
   val="/browse?category=EMBED-FIELD"
   ></script>
```

Use sa5 data format;&#x20;

Add;

* querystring encoding, compat with FS filter&#x20;
* append rather then replace

```html
<script type="sa5:transform:attr"
   target="closest"
   selector="'a'"
   transform="append"
   attr="href"   
   val="EMBED-FIELD"
   encode="querystring" 
   ></script>
```

script type

`sa5:transform:attr` -&#x20;

`target` = closest | ?

selector = CSS selector string used with closest

transform = **`replace`** | `append` | `prepend`

attr = attribute to transform

val = value to use in the transform

encode = none | querystring | url

## Notes&#x20;

Runtime diagnostics are important here.&#x20;


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://attr.sygnal.com/sa5-html/transform.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
