1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<TITLE>hsc - Attribute Assignments</TITLE>
<LINK REV="owns" TITLE="Thomas Aglassinger" HREF="mailto:agi@giga.or.at">
<LINK REL="Next" HREF="expressions.html">
<LINK REL="Copyright" HREF="../copy.html">
<LINK REL="Previous" HREF="syntax.html">
<META name="ROBOTS" content="NOINDEX, NOFOLLOW">
</HEAD>
<BODY>
<A HREF="../index.html"><IMG SRC="../image/main.gif" ALT="Contents" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<IMG SRC="../image/noindex.gif" ALT="-----" ALIGN="middle" WIDTH="70" HEIGHT="16">
<A HREF="../copy.html"><IMG SRC="../image/copy.gif" ALT="Copyright" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="../index.html"><IMG SRC="../image/back.gif" ALT="Up" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="syntax.html"><IMG SRC="../image/prev.gif" ALT="Previous" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<A HREF="expressions.html"><IMG SRC="../image/next.gif" ALT="Next" ALIGN="middle" WIDTH="70" HEIGHT="16"></A>
<HR>
<H1>Attribute Assignments</H1>
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.
<H2>String Constants</H2>
As usual with html, you can use an assignment like
<PRE><IMG SRC="hugo.gif" ALT='hugo'></PRE>
to set the attribute <CODE>SRC</CODE> to ``<CODE>hugo.gif</CODE>'' and
<CODE>ALT</CODE> to ``<CODE>hugo</CODE>''. 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.
<P>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:</P>
<PRE><IMG SRC="quote.gif" ALT='"'></PRE>
<P>Now <CODE>ALT</CODE> contains a double quote as value.</P>
<H2>Constants Without Quotes</H2>
If only certain characters are used, you even can omit the quotes at
all. For example,
<PRE><IMG SRC=hugo.gif ALT=hugo></PRE>
is also legal. As this can cause problems with (very) old browsers, it
might result in <A HREF="../messages.html#message.22">message #22</A>, if <KBD>hsc</KBD> is configured to. However,
the following is not allowed according to the specifications of html:
<PRE><IMG SRC=image/hugo.gif ALT=hugo></PRE>
<P>Because of the slash (``<CODE>/</CODE>'') in the value of <CODE>SRC</CODE>, it would
have been required to put it inside quotes. As this is not the case,
<A HREF="../messages.html#message.81">message #81</A> will show up. Although most browsers can cope with
this, and will use a white space or a greater-than (``<CODE>></CODE>'') as delimiter,
this behavior is not standard.</P>
<H2><A NAME="cond-assign">Compute Expressions</A></H2>
<P>When the assigned value starts with a bracket (``<CODE>(</CODE>''), 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.</P>
A very basic example would be
<PRE><IMG SRC=(name+".gif") ALT=(name)></PRE>
If the attribute <CODE>name</CODE> has been set to ``<CODE>sepp</CODE>'' before,
this will result in
<PRE><IMG SRC="sepp.gif" ALT="sepp"></PRE>
<P>The ``<CODE>+</CODE>'' is used to concatenate two values together.</P>
For more details on this, see the chapter about <A HREF="expressions.html">expressions</A>.
<H2>Conditional Assignments</H2>
<P>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.</P>
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
<PRE>sepp=(hugo)</PRE>
However, if <CODE>hugo</CODE> 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 <CODE><$macro></CODE> or <CODE><$define></CODE>).
Simply use a ``<CODE>?=</CODE>'' instead of the ``<CODE>=</CODE>'' assignment
operator:
<PRE>sepp?=hugo</PRE>
This becomes handy for such macros which are more or less only
extensions of real html-tags:
<PRE>
<$macro MY-BODY BackGround:uri>
<BODY BackGround?=BackGround">
</$macro>
</PRE>
<P>The macro <CODE><MY-BODY></CODE> just inserts a <CODE><BODY></CODE> tag. But
optionally it can also handle the attribute
<CODE>BackGround</CODE>.</P>
<P>But there has not necessarily a <CODE>BackGround</CODE> attribute to
be set when calling <CODE><MY-BODY></CODE>. If you do not specify any,
there also will not be one in the call to <CODE><BODY></CODE> after
the macro has been processed.</P>
Two examples should point out this behavior:
<PRE><MY-BODY></PRE>
will result in
<PRE><BODY></PRE>
but a
<PRE><MY-BODY BackGround='image/backgr.png'></PRE>
will lead to
<PRE><BODY BackGround="image/backgr.png"></PRE>
thus in the second case also adding the attribute
<CODE>BackGround</CODE> to the <CODE><BODY></CODE>-tag.
<P>If <CODE><MY-BODY></CODE> would have been declared without conditional
assignment, it could have looked something like:
<PRE>
<$macro MY-BODY BackGround:uri>
<BODY BackGround=(BackGround)>
</$macro>
</PRE>
If you would try to call it without a <CODE>BackGround</CODE> passed,
this attribute would have been unset, and the attempt to copy the
value of <CODE>BackGround/MY-BODY</CODE> to
<CODE>BackGround/BODY</CODE> using
<CODE>BackGround=(BackGround)</CODE> would result in <A HREF="../messages.html#message.23">message #23</A>
<H2>Complex Conditions</H2>
<P>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:
<PRE>
<$define TEXT:color>
<$if COND=(awfully complex condition))>
<$let TEXT='#123456'>
</$if>
<MY-BODY TEXT?=TEXT>
</PRE>
This also works for <A HREF="spctags.html#let"><CODE><$let></CODE></A>:
<PRE>
<$define sepp:string>
<$define hugo:string>
<$if COND=(awfully complex condition)>
<$let hugo="hugo-value">
</$if>
<$let sepp?=hugo>
</PRE>
and you can also use <A HREF="expressions.html">expressions</A> to compute the source
attribute. For instance, the last line of the above example also could
have been
<PRE><$let sepp?=("hu"+"go")></PRE>
</BODY></HTML>
|