Ric - I have two observations - a minor one and a major one. One is that
your "name" and "class" functions are essentially the same verb with
different arguments; the other is that your difficulty may stem from the
fact that you've buried J's array handling into each function (and are using
the conjunction form to pass multiple nouns instead of verbs and nouns).

I would take a different approach.

First, generalizing the insertion of attributes:

NB.* insAttrib: insert name;value pair x into tagged string y.
   insAttrib=: 4 : 0
   'nm val'=. x
   str=. nm,'="',val,'"'
   whst=. y <./ . i. ' >' NB. insert before first space or closing angle
bracket.
   (whst {. y),' ',str,whst}.y
NB.EG ('class';'c1') insAttrib '<td>0</td>'
)

Then, simplify the initial tagging as this creates the primary noun that
subsequent verbs use as an argument:
TD0=: 3 : '''<td>'',y,''</td>'''

So, for a single item:
   TD0 'hi'
<td>hi</td>
   ('class';'s1') insAttrib TD0 'hi'
<td class="r1">hi</td>

Then, use J to extend to arrays:

   ]aa=. ((<'class');&.>'s1';'s2';'s3') insAttrib&.>TD0&.>(8!:0)i.3 2
+---------------------+---------------------+
|<td class="s1">0</td>|<td class="s1">1</td>|
+---------------------+---------------------+
|<td class="s2">2</td>|<td class="s2">3</td>|
+---------------------+---------------------+
|<td class="s3">4</td>|<td class="s3">5</td>|
+---------------------+---------------------+

   |:((<'name');&.>'n1';'n2';'n3') insAttrib&.>"1 |:aa
+-------------------------------+-------------------------------+
|<td name="n1" class="s1">0</td>|<td name="n1" class="s1">1</td>|
+-------------------------------+-------------------------------+
|<td name="n2" class="s2">2</td>|<td name="n2" class="s2">3</td>|
+-------------------------------+-------------------------------+
|<td name="n3" class="s3">4</td>|<td name="n3" class="s3">5</td>|
+-------------------------------+-------------------------------+

You know what you're trying to do, so you may want to change the form of the
arguments, e.g. the left argument of "insAttrib" could be of the form
'name';'value1';'value2';'value3' or however seems best.

The main things to me seem to be avoiding writing a conjunction just for the
purpose of passing multiple nouns as you seem to have done in your original
example, and using J's array-handling explicitly.

Good luck,

Devon

On 10/28/07, Sherlock, Ric <[EMAIL PROTECTED]> wrote:
>
> I'm trying to create xhtml from J arrays.
>
> Using ~system/packages/publish/web.ijs as a base, I've customised it to
> produce valid xhtml but am having trouble getting the desired result
> when using arrays as arguments.
>
> I've put up the rest of this query on the Wiki because it will be
> formatted better.
>
> Please see http://www.jsoftware.com/jwiki/RicSherlock/XHTML
>
> Please feel free to reply to the list or on the Wiki, whichever you
> prefer.
>
>
> ----------------------------------------------------------------------
> For information about J forums see http://www.jsoftware.com/forums.htm
>



-- 
Devon McCormick, CFA
^me^ at acm.
org is my
preferred e-mail
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to