Categories > [old] TbsOoo & TinyDoc >

formatted replace content

The forum is closed. Please use Stack Overflow for submitting new questions. Use tags: tinybutstrong , opentbs
By: SunWuKung
Date: 2006-07-03
Time: 21:13

formatted replace content

I need to put sentences into a template in such a way that their formatting depends on a value in the array.

Currently I am doing it this way:
[sentences.style_open][sentences.descriptor][sentences.style_close]
but this looks ugly, so I am looking for another way.

I think I would like to do something like [var.formattedsentence].
Than replace it with something like:
$formattedsentence=<text:span text:style-name=[sentence.style]>[sentence.descriptor]</text:span>

and than replace style and descriptor. Is this doable? Would you do it this way?

thanks for the help
SWK
By: Skrol29
Date: 2006-07-04
Time: 11:34

Re: formatted replace content

Hi SWK,

I don't understant why simply code
<text:span text:style-name=[sentence.style]>[sentence.descriptor]</text:span>
in your template is not good?

By: Anonymous
Date: 2006-07-04
Time: 13:58

Re: formatted replace content

You are absolutely right - that should be the proper way, however my visual editor wouldn't let me enter xml tags directly in the text (it escapes them so they actually appear in the output).
By: Anonymous
Date: 2006-07-04
Time: 14:20

Re: formatted replace content

I think the solution would be if I could place an attribute for a tag from a TBS parameter. But I don't think that is possible now...
By: Skrol29
Date: 2006-07-04
Time: 14:23

Re: formatted replace content

I would do it using a parameter "ondata" with a function that create a new column which would be the source you need.

If this happen a lot with your application, you can also create a plug-in to add such a functionality.

If you're using Open Office, you can also ask to Olivier on the forum called [TBS with OpenOffice].
By: SunWuKung
Date: 2006-07-11
Time: 13:24

Re: formatted replace content

the problem comes from the fact that this visual editor (Oo) replaces xml tags with html tags on save
maybe the solution could be creating a function that replaces html tags to xml tags on merge. Than I could simply put the formatting within a TBS tag, so it would look something  like this - syntax is surely wrong but you will get the intent - I would like to call the function on the string between the two brackets
[<text:span text:style-name=[sentence.style]>[sentence.descriptor]</text:span>;ondata=html2xml]
the function itself looks very easy, but I am not sure about the TBS syntax - does this sound a realistic way to you?

thx
SWK
By: SunWuKung
Date: 2006-07-11
Time: 13:49

Re: formatted replace content

btw
this problem is not specific to Oo - I get exactly the same thing (interpreted tags get quoted out) if I use Dreamweaver and copy xml or html content to a html page from the visual interface

By: Skrol29
Date: 2006-07-11
Time: 14:19

Re: formatted replace content

To keep the logic of the template nature (Open Office), you should not put some source of your design on the display level.

I think the feature you need is someting like this:
[sentence.descriptor][sentence.style;ope=xml;changestyle]
You put this snippet in your template and apply any style on it, just in order to have <text:span></> tags around it.
Then, when the  template is merged, parameter "ope=xml" with "changestyle" will change the style attribute.

Something like this has been done with the Excel-XML plug-in.

Such a feature can be done with a plug-in.
I could do it, but I miss time this week.
By: SunWuKung
Date: 2006-07-11
Time: 15:27

Re: formatted replace content

Thanks for your quick answer.
Again - I don't think this problem is specific to Oo, I think we would find this with all visual editors (which is one of the strongest point of TBS).

In order to have different formats applied I will need to store template specific tags somewhere - I can either do it in the template or in the php code as string. I would prefer the template (that was your first suggestion too) since they are template specific - are you suggesting to store them in the php?
Formatting can get quite complex, I am not sure the syntax you are suggesting would allow for that, take the following example where I need to replace style_name and position with two variables.
I think it would be easier to unquote tags than to try to find a syntax that would work for all cases. Currently I am running a function that takes the whole template and replaces all html tags to xml - it works for the time being, but it is far from the ideal solution (for a large number of reasons).


<draw:frame draw:style-name="[style_name]" text:anchor-type="paragraph" svg:x="[position]cm" svg:y="-0.06cm" svg:width="1.55cm" svg:height="0.45cm" draw:z-index="7">
  <draw:image xlink:href="Pictures/10000200000000B70000003528A41862.png" xlink:type="simple" xlink:show="embed" xlink:actuate="onLoad"/></draw:frame>
By: Skrol29
Date: 2006-07-11
Time: 19:20

Re: formatted replace content

Hi,

I agree, it is not specific to Oo. I agree my axemple was specific to Oo but that was a bad illustration.

I think we should not code any snippet source of template on the visual level of the template.
Here is the problem: we want to apply a kind of style over the TBS tag, but such a style needs some "underground" changes to be applied. I can see two interesting ways for doing this.

1/ Define styles in the template, and apply them when needed. (that is what you suggested).
It could be something like this: (source code)
<tag att1=xxx>[define_style;name=style1;block=tag]<tag>
...
[var.x;style=style1]
(Tags names and parameters names are unreal)
When LoadTemplate() is called, [define_style] are searched throught the template source, stored in PHP, and then deleted from the template source.
After that, when a TBS tag is merged and if it has a parameter "style", then both opening tag and closing tag of the style are applied over the TBS tag.

2/ The other way is to apply a style by simply modifying an XML attribute closed to the TBS tag. (That is the way I suggested).
It could be something like this: (source code)
<tag att1=xxx>[var.x;edit_att=att1;newval=style1]</tag>
(Tags names and parameters names are unreal)
When a TBS tag is merged, if this tag has a parameter "edit_att" then this attribute is searched into the preceding XML tag. And it is modified with the given value.
By: SunWuKung
Date: 2006-07-11
Time: 23:44

Re: formatted replace content

Wow, this is a great approach - both of them and yours is way more elegant, and consistent to TBS, so I think that is the way to go.

I would only add two comments to this
- Instead of using edit_att, I think attribute replace should be done as an 'upsert' in database terms:  if the attribute is there its value is replaced, if it is not there it is added with the specified value
- the search range should be definable - eg. if omitted it could be only the directly encapsulating tags but user should be able to extend it by X tags or define it like with other TBS functions - eg. enable to change table attributes from within a cell

In my case the template source would be something like this:

<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>[tag=text:p,var.x,draw:style-name=var.x;svg:x=var.y,DefTag=False]</text:p>

in the visual editor a picture would appear and the text of the TBS tag: [tag=text:p,var.x,draw:style-name=var.x;svg:x=var.y,DefTag=False]

using upsert and defining a search range there may be a situation where we don't know into which tag we should insert the attribute - maybe the outermost (or maybe attributes should be defined together with their tag, or where the last attribute was placed...)

this is very educational to me, unfortunately databases is the only IT area where I have some competence, so I am very sorry but I can't say I would be actually coding this...but I hope you still don't mind having gone through this

thanks
SWK

thx