Generate JSON file from DCR by presentation template
Hello, I am facing the same problem as this post. I need to generate the json file containing the data entries.
I have created a new .tpl file and add the <template> section in templating.cfg. In the new .tpl, I write the json as plain text as it seems good
my .tpl for json output
<iw_pt name="Test">
{"test":{"field1": "<iw_value name='dcr.field1'/>","field2": "<iw_value name='dcr.field2'/>","field3": "<iw_value name='dcr.field3'/>",}}
</iw_pt>
But it doesn't make sense to handle complicated json object in this way. In the .tpl, can I use some json module in Perl for JSON encoding like this
use JSON; my $hash = { Waypoint => { Name => "001", Type => "User", Altitude => "58.441", Depth => "E77 32.647", }, }; my $json_text = encode_json $hash; print $json_text."\n";
I have pasted the above sample code enclosed by <iw_perl> in my .tpl but it does not work.
Any suggestion? Thanks.
Comments
-
My suggestion would be stop using .tpl and start using XSLT for your transformations - it is so much easier and more straightforward.
0 -
hi David,
Thank you for you suggestion. It is a great hint. I have tried using xslt to convert some simple dcr to json.
e.g.
xslt:
<?xml version="1.0" encoding="UTF-8" ?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="text" encoding="utf-8"/> <xsl:template match="/"> {<xsl:for-each select="record/item"> "<xsl:value-of select="@name"/>":"<xsl:value-of select="value"/>" <xsl:if test="position() != last()">,</xsl:if> </xsl:for-each>} </xsl:template> </xsl:stylesheet>
testing dcr:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE record SYSTEM "dcr4.5.dtd"> <record name="dateType1" type="content"> <item name="field1"><value>value1</value></item> <item name="field2"><value>value2</value></item> </record>
converted json:
{ "field1":"value1" , "field2":"value2" }
But it will be difficult for my level to write a generic xslt to handle both simple and complicated dcr, which may has nested item/value structure. I need to handle more than 20 dct...
e.g.
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE record SYSTEM "dcr4.5.dtd"> <record name="dateType1" type="content"> <item name="section1"><value>value0</value></item> <item name="section2"/> <item name="section3"> <value> <item name="field1"><value>value1</value></item> <item name="field2"><value>value2</value></item> </value> </item> </record>
0 -
I didn't know XSLT or any templating at all either until I started working here at this latest company - prior to that I only worked with TeamSite/OpenDeploy with no templating at all. It is possible to learn XSLT pretty quickly using Google searches and tutorials. I just believe it is so much easier to transform complex XML to JSON structures using XSLT. I doubt there is a lot of documentation on TPL out there. Anything proprietary that is specific to this product will be difficult to find documentation on - all the experts in the field don't post here anymore or have retired. OpenText doesn't seem to allow their engineers to provide any help here either, however useful that would be to the customer base. Interwoven did a great service to the customer base back in the day by having their engineers post on DevNet to help customers. Interwoven got a lot of things right that none of the companies that purchased the product ever figured out. But that's not going to help you get your DCRs transformed - I would just do your best to either really take some time to hardcore learn XSLT (maybe your company will pay for a course) or take an online course yourself, or just hit Google hard - everything you need to do is out there. Someone has done anything you need to do.
0
Categories
- All Categories
- 122 Developer Announcements
- 53 Articles
- 151 General Questions
- 147 Thrust Services
- 56 OpenText Hackathon
- 35 Developer Tools
- 20.6K Analytics
- 4.2K AppWorks
- 9K Extended ECM
- 917 Cloud Fax and Notifications
- 84 Digital Asset Management
- 9.4K Documentum
- 31 eDOCS
- 181 Exstream
- 39.8K TeamSite
- 1.7K Web Experience Management
- 8 XM Fax
- Follow Categories
- Docker Automation
- LiveSite Content Services (LSCS) REST API
- Single Page Application (SPA) Modules
- TeamSite Add-ons
If you are interested in gaining full access to the content, you can register for a My Support account here.