Custom Rule Replace Scriptlets

Sample Replace scriptlets are provided with the Astoria system.

Sample Replace scriptlets are included in starScriptlets.py.

addApprovalLabel(approvalLabel, approvalDateStr = None)

Note: This scriptlet operates on snapshot labels, formerly called approval labels.

Adds a snapshot label (approvalLabel) to the current object. If specified, the approvalDateStr specifies a cryptic numeric time string. Contact Astoria Support for assistance.

For example, use addApprovalLabel("Omega") to add a snapshot label Omega.

addPlatform(platformStr)

Adds a <platform> element as the last child of the context (e.g. <prodinfo>) element. The content of the platform element will be the value of the platformStr parameter.

addProduct(productStr, versionStr)

Given a productStr (for example, new-shared-product) and a version string (for example, 10.2), adds a <prodinfo> element with appropriate child elements having the specified values before <othermeta> if present, or as the last child of the context (<metadata>) object.

addVersion(versionStr)

Given a versionStr (for example, 10.2), adds a <vrm> element as the last child of the context element.

addXML(xmlFragmentString, position=-1)

Adds the specified XML fragment at the specified position, relative to the content object. The XML fragment will be made a child of the context element.

The relative position defaults to last child, but could be any child position:
  • A position value of 0 indicates first child.
  • A position value of 1 indicates after the existing first child of context object.
  • A position value of -1 indicates last child of context object.
  • A value of -2 indicates that fragment is inserted before the last child.
For example, to append a paragraph "Hello World" as the last child of the selected section, specify the following custom replace string:
addXML('<p class="fooClass">Hello <i>World</i></p>')
Note:
  • Use single quotes to surround the xmlFragmentString argument.
  • Use double quotes to surround XML attribute values within the XML fragment string.
The XML fragment does not have to be a single element. The following are legal:
  • Nested elements:
    <p>Hello <b>World</b></p> 
  • Multiple top-level elements:
    <p>First paragraph</p><p>Second paragraph</p>
  • Leading or trailing PCDATA:
    hello <b>World</b>, how are you?
To add a DITA linking element (conrefs xref, image), specify the appropriate attributes, with a valid repository WEBDAV URL. You can generate this URL from the WAN editor. If you create a conref/href in your editor using the Astoria menu, you’ll see that the href attribute has a value something like:
“http://shrike/astoria/_id_00000018WIA33D06910GYZ_conrefA1.dita#conrefA/para”
Use this value in the XML fragment string:
<conref href="http://shrike/astoria/_id_00000018WIA33D06910GYZ_conrefA1.dita#conrefA/para/">
You can also use the folder item path syntax instead of the ID syntax:
<conref href=http://shrike/astoria/DITA/Translation Testing/Approval/conrefA1.dita#conrefA/para/>
In either case, it is critical that you include the trailing fragment string (#conrefA/para), if you wish to reference a specific element.
Replacing with a link to a graphic file works similarly, just without the trailing fragment string. You can also use the ID syntax for a graphic file:
<image href="http://shrike/astoria/DITA/Translation Testing/Effectivity/basediag3.gif"/>

repairConrefByGUID(optionalGUID = None, optionalFragmentIDs = None)

Changes conref references to a different target.
Important: This scriptlet works only for elements with conref attributes.
See GS Example: Migrate Conref References to a Different Document.

The Replace With parameter specifies the optionalGUID and optionalFragmentIDs of the replacement document.

Here is how the parameters interact:
optionalGUID value optionalFragmentIDs value Results
None None Invalid
None newID/subID A different element in the same document is targeted.
newGUID None The element in a new replacement document having the same id/subid is targeted.
newGUID newId/subId The element with the specified newId/subId in the new replacement document is targeted.

setCustomAttribute(attributeName, oldValue, newValue, allowDuplicateValues = 0 )

Sets custom attribute values.

The attributeName parameter specifies the name of the custom attribute definition of interest.
  • oldValue is the value the custom attribute must have if a substitution is to be performed. Specify None to indicate it doesn't matter what, if any, oldValue must exist.
  • newValue is the value that will be set. Specify None if the existing custom attribute value should be removed.
The allowDuplicateValues parameter indicates whether multiple values are allowed.
  • Specify 0 if only a single value is to be present.
  • Specify 1 if the new custom attribute should be added.