Re: problems using the pphash "set"
Daniel Dekany <[email protected]> Thu, 3 Jun 2004 15:43:10 +0200
| Newsgroups | gmane.comp.text.fmpp |
|---|---|
| Message-ID | <[email protected]> |
Thursday, June 3, 2004, 3:38:52 PM, Asad Niazi wrote: > hello! > I needed your help regarding the pphash "set". > It is mentioned that we can change the values present in a writable Hash > with this command. Now it seems to work for the case when we want to change > the value of the first hierarchical element. Let me give u an example and > explain the problem. I have stored an element (which itself is a hash) from > XML file into a writable hash using this pphash "set". > > <pp.set hash=Hash key="Syntax" value=node.syntax /> > > The structure of this "syntax" element (from node) in the XML file looks > like : > > <syntax> > <typedef basetype="Enumeration"> > <namednumber name="sonet" number="1"/> > <namednumber name="sdh" number="2"/> > </typedef> > </syntax> > > As you can see that there are a few attributes present. Now I want to change > the values of these attributes. I have tried giving different values in the > "key" parameter e.g. key="Hash.Syntax.typdef.@basetype" > and giving the value that i want, in the value parameter, but it doesnt > work. When i print the value using the "pp.warning", it gives the original > values that were stored when i used the first set command to save the > node.syntax. I doesn't dies with error, just silently does nothing? > I am really getting desperate regarding this problem, i know there is a way > to change the values but i cannot seem to figure out how. > I would really appreciate if you can email me the solution to this problem. > Thanking in Anticipation. I'm afraid I have bad news... Set operations only work on "writable hashes" and "writable sequences". "writable sequences" and "writable hashes" are the variables that you made with pp.newWritableSequence and newWritableHash. (Now that I read back pphash.html#sect43, it could be explained more understandably...). The reason of this is that FreeMarker sequence and hash type is read-only. So, for an arbitrary variable that implements the hash and/or sequence type (which are, technically, FreeMarker specific Java interfaces), there is no way to modify it. What to do then? You should not *need* to modify loaded data, at least not in the templates. From the viewpoint of a template, the loaded data represent the content of an abstract data source, so in principle it doesn't make sense to change it. The data is a "fact", graved into stone. Then the template can work on displaying it. I know it's such a academical bullshit, but the MVC-ish approach of FreeMarker suggest this, so if you try to break the base approach of a tool, you will most certainly run into problems. (The writable hashes/sequences were added to create complex temporary variables (work variables) that you use during template execution.) So if you look at the solvable problem with MVC-ish eyes, maybe you were choose a different logic for the project, where simply it never occurs to you to modify the XML... maybe... Say, it can be a good idea to push complex calculations to the data loader (i.e., mostly, write BSH scripts to prepare the data to display), rather than trying to solve them in templates, since templates are for displaying something data and not for calculating data. > Best Regards > Asadullah Khan Niazi -- Best regards, Daniel Dekany ------------------------------------------------------- This SF.Net email is sponsored by the new InstallShield X. From Windows to Linux, servers to mobile, InstallShield X is the one installation-authoring solution that does it all. Learn more and evaluate today! http://www.installshield.com/Dev2Dev/0504