Home
TeamSite
Reformatting existing DCRs
alanhill
Hi,
I'm sure this must have come up somewhere before...
I'm amending a datacapture.cfg file and as part of this I need to amend the structure of the xml that is saved in the DCR. As an example..
An existing DCR looks like:
<item name="Main">
<value>
<item name="Content">
<value>some text here</value>
</item>
</value>
</item>
whereas a new one wants to look like:
<item name="Body">
<value>
<item name="Formatted_Content">
<value>
<item name="Content">
<value>some text here</value>
</item>
</value>
</item>
</value>
</item>
The change basically was to add an option to allow users to create a formatted content box, or a plain content box, at present they can only create formatted content.
To allow this to be as efficient as possible, I need to amend any existing DCRs (using formatted content) to match the xml structure of new DCRs. This will then allow these dcrs to be edited with the new template without losing any data.
I was planning to write a perl script that as a one-off could search the templatedata folders and identify applicable dcrs. This is fairly easy, but actually reformatting the xml is proving a little tricky.
Does anyone have any scripts that have something similar in the past that they could provide me, or have any ideas of better ways to do this reformatting (a lovely visual way of dragging an existing element onto it's new equivalent would be lovely but I wouldn't imagine Interwoven have anything like that - please prove me wrong Interwoven).
Many thanks folks...
Teamsite Template Developer
Find more posts tagged with
Comments
jbonifaci
If you are just adding a new item, you do not need to add it to your DCRs, unless you want to pre-populate it with something. If you are just trying to add an empty item, don't worry about it, it isn't needed. You should still be able to open all existing DCRs and everything should work fine, your new item will show up and be empty. As long as you haven't changed the names or structures of your existing items, you don't have to worry.
If you find you need to manipulate your DCRs, you'll need to write a script to modify each one using your favorite xml manipulation method. I always prefer doing everything with regex's for performance reasons, but feel free to use your favorite xml parser to do this as well. All you're really doing is manipulating some text, it's pretty simple stuff once you actually sit down and do it.
~Jeff
alanhill
Jeff,
Agreed - if we were just adding new items into the DCR (which we've done loads of in the past) I wouldn't worry at all. This exmaple is all about reformatting the existing items to fit the new datacapture.cfg structure.
I've worked with reg exps for years, so that's how I was planning to do it initially. I also found a few posts and KB articles on the xml parser in Teamsite so wondered if that was also an option.
Regular expressions do seem a little easier as you suggest, especially as I've got a load of experience with them, but I figured someone else out there must have done something similar before.
How useful would it be to actually have a 'Convert Existing DCRs' menu option in Teamsite which, given the old and new datacapture.cfg files coud reformat the existing dcrs to match the new format.
Teamsite Template Developer
Adam Stoller
An existing DCR looks like:<item name="
Main
">
<value>
<item name="Content">
<value>some text here</value>
</item>
</value>
</item>whereas a new one wants to look like:<item name="
Body
">
<value>
<item name="Formatted_Content">
<value>
<item name="Content">
<value>some text here</value>
</item>
</value>
</item>
</value>
</item>
You're doing more than just adding an element to the structure here. You're changing the name of the root container
and
you're
changing
the structure of the DCR - which means any existing DCRs that have values for "Content" will no longer find it - thus not only are you changing the DCT - you would need to modify
every
pre-existing DCR to match it.
How useful would it be to actually have a 'Convert Existing DCRs' menu option in Teamsite which, given the old and new datacapture.cfg files coud reformat the existing dcrs to match the new format.
Useful - absolutely.
Do-able OOTB - unlikely - at least not without a well defined method for specifying the before/after structure mappings. In the case above - you'd want something like:
Main => Body
Main.Content => Body.Formatted_Content.Content
and the code would have to figure out that it needs to create a new node "Formatted_Content" and insert the existing "Content" node within it.
It gets even trickier when dealing with changes to/from replicants (I'm working on hacking some code right now to do this kind of thing - it ain't pretty - I'm sure there's a "better way" - but it's difficult to find it and still meet deadlines...) My guess would be XSLT, but as I don't have a lot of experience with it, it would take me longer to do that then hack my way through it using TeamSite:
CRnode and regex's...(note: if anyone is willing to share some "good" code for dealing with DCR restructuring - I'm willing to look at it and try it out)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
jed
You might want to look into using XSLT to perform some of the reformatting. A lot of the templating folks in my group use that for batch reformatting.
--
Jed Michnowicz
jedm@sun.com
Content Management Engineering
Sun Microsystems
Adam Stoller
If anyone cares to post a tutorial on using XSLT to do this kind of thing - I'd be interested in reading it.
I "kind of know" what it does, but not having used it, it's not quite as easy to "pick up".
I think one of the pieces I need to understand is how to "run it" - i.e. Perl script are run via perl. How is XSLT run? (I have a feeling it's a "simple" answer, but ...)
--fish
Senior Consultant, Quotient Inc.
http://www.quotient-inc.com
RonaldV
Yep,
you need "something" to run the xslt. This something can be:
- your browser
- many professional xml-editors
- perl (see:
http://xmlxslt.sourceforge.net/
or
http://www.gingerall.com/charlie/ga/xml/p_sab.xml
)
- java (see
http://xml.apache.org/xalan-j/
)
- others (see
http://www.google.com/Top/Computers/Data_Formats/Markup_Languages/XML/Style_Sheets/XSL/
)
Many xslt tutorials exists (see link above) but I've found that understanding (and writing your own) xslt is not that easy.
Does anybody have some demo-code that does this sort of this for a dcr?
Good lukc, Ronald
TS65 Sp1
Win2k Sp4
OD602
Johnny
TeamSite ships with Apache Xalan
`iwgethome`/bin/XalanTransform
John Cuiuli
jed
Sorry, no good demo code, but these tutorials/refs got me through some transforms in the past:
http://www.zvon.org/xxl/XSLTutorial/Books/Book1/
http://www.zvon.org/xxl/XPathTutorial/General/examples.html
http://www.zvon.org/xxl/XSLTreference/Output/index.html
--
Jed Michnowicz
jedm@sun.com
Content Management Engineering
Sun Microsystems
alanhill
Jed,
Thanks for the feedback, I'd never really thought of using xslt, not something I've too much experience of, so I'll read into it a little.
Teamsite Template Developer
alanhill
Fish,
You're quite right I am fundamentally changing the structure of the datacapture.cfg, and as such it's necessary for me to reformat the existing dcrs so that their data is retained.
Another option I just thought of was to run a script which got the existing values out of the existing dcrs, then actually dynamically created new dcrs using OOTB Teamsite functionality, as opposed to trying to "manually" create a new dcr format to match the new datacapture.cfg. After all the new cfg file is there ready to be used to create dcrs so this might be a way of doing it. It also might be a way of allowing a relatively efficient bespoke file menu process to be created which would allow it to be done again for another dcr.
I'll investigate and post any results for everyon'es benefit/perusal.
Cheers
Alan
Teamsite Template Developer
RonaldV
Hi,
I'm no xsl-expert but here what I've come up with:
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="record">
<root>
<xsl:apply-templates>
<xsl:sort select="
@name"/>
;
</xsl:apply-templates>
</root>
</xsl:template>
<xsl:template match="item">
<xsl:element name ="{
@name}">
;
<xsl:apply-templates/>
<!-- Content: template -->
</xsl:element>
</xsl:template>
<xsl:template match="value">
<xsl:apply-templates/>
</xsl:template>
</xsl:stylesheet>
To use xerces to do the work for you run this:
set classpath = c:\xsl\xalan\xalan.jar;c:\xsl\xalan\xercesImpl.jar;c:\xsl\xalan\xml-apis.jar;c:\xsl\xalan\serializer.jar;
"C:\Program Files\Java\j2re1.4.1_02\bin\java.exe" org.apache.xalan.xslt.Process -in ps1.75.60.dcr -xsl dcr2xml.xsl
It's somewhat untested code but looks pretty simple and plain. :-) Any improvements are welcome.
Makes you wonder why Iwov does not include a script like this, hé?
Ronald
TS65 Sp1
Win2k Sp4
OD602
jbonifaci
In reply to:
Makes you wonder why Iwov does not include a script like this, hé?
First, it's not as easy as just saying it, there are an infinite number of ways one DCT could map to another, so it would have to highly customizable. Second, this is a simple process that can be coded by a developer for their specific needs in a few hours at most. Why provide an overly complex solution that likely wouldn't fit everyone's needs for a simple problem?
~Jeff
RonaldV
Ok Jeff,
I have to admit that I misread the inital post. To that you are right.
I answered a different question and was thinking it refered to converting the 5.x-type dcr's to the new 6.x-xml-type dcr's. That is the question that my answer refers to.
But nevertheless I think that when Iwov introduces a new dcr-format they should include a way to convert your existing data. It's not like they give a way a TS-license with a new bought pack of butter. ;-) And to that my remark about why Iwov does not come up with this script still holds.
Tha, Ronald
TS65 Sp1
Win2k Sp4
OD602