Categories > OpenTBS with DOCX >

attribute values

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: SunWuKung
Date: 2006-10-16
Time: 15:05

attribute values

I would need to replace an attribute value in a block with a value that depends on a block field. So far I found no nice solution.

I can use ondata - but than I need to use formatting tags as strings in the php eg. the ondata example on the site is changing the color of the text this way.


if ($CurrRec['res_score']>=100) $CurrRec['level'] = '<font color="#669933">middle</font>' ;
  if ($CurrRec['res_score']>=200) $CurrRec['level'] = '<font color="#3366CC">good</font>' ;

Do you have a suggestion?
Thanks for the help.
SWK


 
By: Skrol29
Date: 2006-10-16
Time: 16:05

Re: attribute values

Can you precise which tag you'd like to change and when?
By: SunWuKung
Date: 2006-10-25
Time: 09:36

Re: attribute values

In the ondata example there is a table. In the level column the content of the cell could be something like this. My question is:
If I have the color value in my php array how could I put a TBS tag in place of good so that it would replace the value of color.


<div align="center"><font color="#3366CC" margin="1 cm">good</font></div>

I would like to avoid using presentation specific code in the php - as it is done in the example php script:

if ($CurrRec['res_score']>=100) $CurrRec['level'] = '<font color="#669933" margin="1 cm">middle</font>' ;

Is it possible to create an ondata function that would replace the value of the attribute?

e.g. ondata=m_event_b1((color=%,b1.color),(margin=%,b1.margin))

Here it adds little value but I usually work with xml files where this is a frequent problem and a TBS block may contain many attribute value that I would like to manipulate.

e.g. In the following xml segment it would be much nicer to use a function to replace attribute values, than include the whole thing in php, manipulate it as a string and place it back.
<text:p>
<draw:frame draw:style-name="fr1" draw:name="graphics1" text:anchor-type="paragraph" svg:width="1.549cm" svg:x="5cm" svg:height="0.448cm" draw:z-index="0">
<draw:image xlink:href="Pictures/10000000000000B70000003562694B3C.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/>
</draw:frame>[block=text:p;ondata=m_event_b1((svg:x=%,b1.xpos),(svg:width=%,b1.width))]</text:p>

Thanks for the help.
SWK
By: Skrol29
Date: 2006-10-26
Time: 02:26

Re: attribute values

Hi SWK,

Hooww, you're working with a OpenOffice document, and you'd like to not place TBS tags in the internal part of the template which is not viewable when you edit it through OO.

We had exactly the same kind of problem for the Excel plug-in. This plug-in deals with an XML file, and sometime TBS fields must affect the XLM attributes.
The function you're asking for is existing in a certain way in this Excel plug-in, but it is big. And it assumes that there is no extra TBS tags between the TBS tag with the value and the attribute to change.

Maybe such a feature will be inserted into TBS because working with XML document happens more and more often.
But now, I can only suggest to place TBS tags in the attributes, or to take a look at the Excel plug-in.
By: SunWuKung
Date: 2006-10-26
Time: 09:41

Re: attribute values

Do you think it would be possible to make a quick and dirty solution using ondata and GetBlockSource?

Ondata would call a function for each row. In the function I would look up the source code of the block, do a replace based on the arguments of the ondata function and write it back.

Does this sound doable?
Thx.
SWK
By: Skrol29
Date: 2006-10-26
Time: 18:03

Re: attribute values

I think a plug-in that enhances parameter "ope" can be good.
[var.x;ope=loc;att=href]
or
[var.x;ope=loc;att=href;tag=img]
This should move the TBS tag before it is merged.
What do you think ?
By: SunWuKung
Date: 2006-10-26
Time: 22:37

Re: attribute values

If I understand this it is basically a syntax for find/replace within tag.
- find the value of href
- replace found value with the value of var.x
- within the range of the img tag

I think it is a very good idea I would add that when you need to manipulate multiple attributes this could get very long. Instead of a single value I would allow an array of find/replace pairs to process in one tag.
I don't remember this but can you append a string to var.x - eg if the value 12 comes from the db but I would like to add the pt after that to get: line-height="12pt"

Another drastically different approach could be to insert the all of the objects with their attributes into the document and somehow make TBS to delete all of them but one. For this I would need to be able to numerically pass TBS which is the tag I want to keep.

One of my constant headache is that I need to create profiles: a number of scalesnames with a value from 1 to 10. Now I create a nice table - scalename, scalevalue, and than I have to insert a picture on the 1 to 10 position. This either requires me to manipulate some x position attribute of the picture or I could insert 10 rows with the pictures already in place and when the value comes eg.3 I would delete rows 1-2 and 4-10.
By: Skrol29
Date: 2006-10-30
Time: 18:17

Re: attribute values

> I think it is a very good idea I would add that when you need to
> manipulate multiple attributes this could get very long. Instead of a
> single value I would allow an array of find/replace pairs to process in one tag.

But you cannot use such an array when the data comes from a database.

> Another drastically different approach could be to insert the all of
> the objects with their attributes into the document and somehow
> make TBS to delete all of them but one.

I don't understand this one. How will you make a shape (for example) be positioned depending to data stored in a database ?

For your last problem about profiles, bay be the better way is to have a solution which enables you to retrieve properties of XML items.

By: SunWuKung
Date: 2006-10-30
Time: 20:02

Re: attribute values

1. I think you can create an array from the column values - eg. the record can have a columns for href, xsize and ysize. So I can create the TBS values i.href, i.xsize, i.ysize and pass this to the ope function as [i;block=img;ope=loc;att=((href;i.href),(xsize;i.xsize),(ysize;i.ysize))]

2. All xml based presentation engines that I looked at has some attribute to position pictures. In the ODT example above I need to replace svg:x="5cm" with svg:x="[i.xpos]cm" and its done. But a similar attribute would do it in docx for Word2007, or an OpenLaszlo presentation file. These all have visual editors. TBS is fantastic for these. I miss the ability to manipulate attributes and keep looking for workarounds.