Attribute Assignments

When assigning new values to attributes, you can use string constants, like in html. Furthermore, you can also use expression to compute a new value depending on certain things. And there you can make the assignment of a value depend on the value of another attribute.

String Constants

As usual with html, you can use an assignment like
<img SRC="hugo.png" ALT='hugo'>
to set the attribute SRC to ``hugo.gif'' and ALT to ``hugo''. The first assignment uses double quotes to denote the string boundaries, the second one uses single quotes. There is no difference in the functionality between these to kinds of quotes.

Again, like in html, one kind of quotes might show up inside a string, as long as it is quoted with other kind, for example:

<img SRC="quote.png" ALT='"'>

Now ALT contains a double quote as value.

Numeric Constants

As you can see in the description of attribute types, hsc distinguisches between string attributes and numeric attributes. Different from most other languages, it requires these to be quoted just like strings. The reason for this seemingly strange convention is that HTML allows attribute names to start with a number, so while other languages can just assume that anything starting with a digit is not a variable name, hsc can not. If an operator requires a numeric argument, it will just take the ``string'' (i.e. quoted) argument and try to convert it to an integer.

Constants Without Quotes

If only certain characters are used, you even can omit the quotes at all. For example,
<img SRC=hugo.gif ALT=hugo>
is also legal. As this can cause problems with (very) old browsers, it might result in message #22, if hsc is configured to. However, the following is not allowed according to the specifications of html:
<img SRC=image/hugo.gif ALT=hugo>

Because of the slash (``/'') in the value of SRC, it would have been required to put it inside quotes. As this is not the case, message #81 will show up. Although most browsers can cope with this, and will use a white space or a greater-than (``>'') as delimiter, this behavior is not standard.

Compute Expressions

When the assigned value starts with a bracket (``(''), it denotes an expression to be computed before its result is used as new value. There are several operators you can use for that, and of course you also can refer to other attributes.

A very basic example would be
<img SRC=(name+".gif") ALT=(name)>
If the attribute name has been set to ``sepp'' before, this will result in
<img SRC="sepp.png" ALT="sepp">

The ``+'' is used to concatenate two values together.

For more details on this, see the chapter about expressions.

Using Quotes Inside Quoted Strings

There are two kind of quotes you can use for string constants, namely single quotes (') and double quotes ("). You can use the one inside of the other just as a normal character:

<img SRC="single.png" ALT="a single (') quote">
<img SRC='double.gif' ALT='a double (") quote'>

Note that this is no ``escape mechanism'', the other quote just is treated as a normal character. For the normal user, this should be all you want to know about ``quotes inside quotes''. Freaky ones, read on.

Because of the limitations of html, it is not possible to use both kind of quotes in one value. However, in hsc you could use string concatenation to push both quotes into one value:

<$define sepp:string=("a single (') quote"+' and a double quote (") together')>

The value of sepp then would be >>a single (') quote and a double quote (") together<<. Different to html, hsc doesn't mind about that internally. The trouble starts when you assign the value later on to an attribute of an HTML tag:

<img SRC="sepp.png" ALT=(sepp)>

Now hsc can't use neither single nor double quotes to assign the value of sepp to ALT. To solve that problem, it uses double quotes to embed the value in and replaces all double quotes inside by its entity &quot;, thus resulting in:

<img SRC="sepp.png" ALT="a single (') quote and a double quote (&quot;) together">

Note that several browsers are too stupid to display this correctly.

Conditional Assignments

This paragraph deals with a feature you probably do not want to use (and understand) before you understood how those macros work. You can skip this part for now and return later.

You can easily let an attribute obtain it's value from another attribute. For example, within a tag call you can use an assignment like
However, if hugo has not been defined and assigned a value before, this will result in an error message. Conditional assignments now only assign a value to the target attribute, if the source attribute has been set; in any case, the source attribute must have been defined before (using <$macro> or <$define>). Simply use a ``?='' instead of the ``='' assignment operator:
This becomes handy for such macros which are more or less only extensions of real HTML tags:
<$macro MY-BODY BackGround:uri>
    <body BackGround?=BackGround">

The macro <MY-BODY> just inserts a <BODY> tag. But optionally it can also handle the attribute BackGround.

But there has not necessarily a BackGround attribute to be set when calling <MY-BODY>. If you do not specify any, there also will not be one in the call to <BODY> after the macro has been processed.

Two examples should point out this behavior:
will result in
but a
<my-body BackGround='image/backgr.png'>
will lead to
<body BackGround="image/backgr.png">
thus in the second case also adding the attribute BackGround to the <BODY>-tag.

If <MY-BODY> would have been declared without conditional assignment, it could have looked something like:

<$macro MY-BODY BackGround:uri>
    <body BackGround=(BackGround)>
If you would try to call it without a BackGround passed, this attribute would have been unset, and the attempt to copy the value of BackGround/MY-BODY to BackGround/BODY using BackGround=(BackGround) would result in message #23

Complex Conditions

On the first sight, it might seem that there is only the simple condition ``if attribute is set..'' possible. But no one prevents you from using code like this:

<$define TEXT:color>
<$if COND=(awfully complex condition))>
    <$let TEXT='#123456'>

<my-body TEXT?=TEXT>
This also works for <$let>:
<$define sepp:string>
<$define hugo:string>

<$if COND=(awfully complex condition)>
    <$let hugo="hugo-value">

<$let sepp?=hugo>
and you can also use expressions to compute the source attribute. For instance, the last line of the above example also could have been
<$let sepp?=("hu"+"go")>