About Arbortext Styler > Extending Stylesheets > Overview of Autogenerated PTC ALD Source
  
Overview of Autogenerated PTC ALD Source
When you choose to edit the source of an object for PTC ALD, PTC ALD will generate a prescribed set of source based on the object you are editing, and its current settings for certain properties. The source is written in JavaScript and based on objects defined in PTC Arbortext Layout Developer’s Formatting Object Model (FOM). You will then add your own edits to that generated source. This topic takes a context from a sample stylesheet and describes the default source generated for a context by Arbortext Styler.
* 
You are not permitted to edit the source of a whole element for PTC ALD; you can only edit it at context level.
The stylesheet referenced in this section is axdocbook.style, accessed by electing to create a sample Arbortext XML DocBook 4.0 (axdocbook) file and choosing to edit its stylesheet. Once you have opened the stylesheet, select the context title in sect1 then elect to edit its source for PTC ALD with the menu option Edit > Edit Context Source > PTC ALD. The source will open in the Source Editor window.
The menu option is only available if your stylesheet to use PTC ALD as its print/PDF engine.
Each section below provides a snippet of autogenerated code from the sample stylesheet and briefly describes its purpose.
OnEnter command
<OnEnter type="application/x-javascript" xml:space="preserve">
// onEnter processing for context: sect1/title
The OnEnter command is marks the start of the context. It contains the instructions for processing the context, as described in the next sections (with the exception of the OnExit command).
Context preamble
formatting.fishSave( template.stylerFish );
var block = new fBlock();
var paragraph = block.defaultParagraph;
var style = block.defaultStyle;
var graphic = {};
var useGraphic = false;
var isBlock = -1;
formatting.fish[ template.stylerFish ]['isBlock'] = 0;
formatting.fish[ template.stylerFish ]['isHidden'] = 0;
formatting.fish[ template.stylerFish ]['startNew' ] = 0;
formatting.fish[ template.stylerFish ]['pageSet'] = '';
formatting.fish[ template.stylerFish ]['pageType'] = 0;
formatting.fish[ template.stylerFish ]['pageNumber'] = 0;
formatting.fish[ template.stylerFish ]['wantColumnTopMargin'] = 0;
formatting.fish[ template.stylerFish ]['customTable'] = 0;
formatting.fish[ template.stylerFish ][ 'markerType' ] = '';

// context preamble complete.
This section provides two sets of information that may be used later in the code. It sets up the object and defines variables to hold settings made in certain areas of the Arbortext Styler UI. Note that there is a default set of variables for each object type you are permitted to edit, and the same set will be created in source for every object of a certain type. In this example, these are the variables that are set up for an element context.
Object :
var block = new fBlock();
The code sets up a new block and provides the variable that will hold the block information.
Variables:
var paragraph = block.defaultParagraph;
var style = block.defaultStyle;
var graphic = {};
var useGraphic = false;
var isBlock = -1;
formatting.fish[ template.stylerFish ]['isBlock'] = 0;
formatting.fish[ template.stylerFish ]['isHidden'] = 0;
formatting.fish[ template.stylerFish ]['startNew' ] = 0;
formatting.fish[ template.stylerFish ]['pageSet'] = '';
formatting.fish[ template.stylerFish ]['pageType'] = 0;
formatting.fish[ template.stylerFish ]['pageNumber'] = 0;
formatting.fish[ template.stylerFish ]['wantColumnTopMargin'] = 0;
formatting.fish[ template.stylerFish ]['customTable'] = 0;
formatting.fish[ template.stylerFish ][ 'markerType' ] = '';

The code defines the variables that will hold default style and paragraph properties, and values set in certain areas of the Arbortext Styler UI. Each of these corresponds to a set of conditions by which properties are applied in later sections of the code.
Note the presence of var isBlock – this variable will hold a value that reflects the setting in the Structure type field of the Breaks category for the context. If this value receives a value of -1, this means that the Structure type field has not been set for the context and, as such, properties set for the context via property set(s) will take precedence over others. If the context has a defined structure type of Block or Inline, where this variable will receive a value of 0 or 1, property sets cannot override other settings. See the entry for Properties defined via UI below for the way in which this setting will appear when the context has a structure of Block.
Property set information — all outputs
template.content.functions[ template.stylerNamespace ].PropertySet['title']( block );
template.content.functions[ template.stylerNamespace ].PropertySet['Title_3']( block );
This section describes property sets that has been assigned to the context for all outputs.
Referring to the sample axdocbook.style, for Base (All Outputs), you will see that the title in sect1 context has two property sets assigned:
1. title
2. Title 3
Properties defined via UI – all outputs
block.indent = '-0.00pt';
block.indentStart = '0.00pt';
block.absoluteStart = 0;
formatting.fish[ template.stylerFish ]['isBlock'] = isBlock = 1;
var markerArgs = { followWith : "&#x20;", format : "(PREVIOUS) '.' (CURRENT)", labelPlacement : "beforeNumber", numberStyle : "1", countAs : "title0BA755AB" };
formatting.fish[ template.stylerFish ]['markerType'] = 'Numbering';
if ( !formatting.evaluateXPath( 'x3b2:get-userdata( "_temp_hasbefore_" )' ) != 0 )
{
if ( template.content.getStream('axdocbook_sample:Element:title:title_in_sect1:addBefore') == null )
{
var stream = template.content.createStream( 'axdocbook_sample:Element:title:title_in_sect1:addBefore', fTag.TYPE_EDITOR_TREE );
stream.write( "<?xml version=\"1.0\"?><Gentext xmlns:_dtd=\"\"
xmlns:_gte=\"http://www.arbortext.com/namespace/Styler/GeneratedTextElements\"
xmlns:_sfe=\"http://www.arbortext.com/namespace/Styler/StylerFormattingElements\"
xmlns:_ufe=\"http://www.arbortext.com/namespace/Styler/UserFormattingElements\"
xmlns:atidlm=\"http://www.arbortext.com/namespace/atidlm\"
xmlns:ch=\"http://www.arbortext.com/namespace/chunker\"
xmlns:rtf=\"http://www.cambridgedocs.com/namespace/fo/rtf\"
xmlns:saxon=\"http://saxon.sf.net/\"
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><_sfe:BeforeOrAfterText>
<_gte:LabelAndNumberMarker><_gte:Font><_gte:ElementNumber display=\"#.1\"/></_gte:Font>
</_gte:LabelAndNumberMarker></_sfe:BeforeOrAfterText></Gentext>" );
}
formatting.evaluateXPath( 'x3b2:clear-before( self::node())' );
formatting.evaluateXPath( 'x3b2:add-before( "axdocbook_sample:Element:title:title_in_sect1:addBefore",
1, self::node())' );
formatting.evaluateXPath( 'x3b2:set-userdata( "_temp_hasbefore_", "1" )' );
var hasTOCEntry = formatting.evaluateXPath( 'x3b2:get-userdata( "app_tocEntry" )' );
if ( hasTOCEntry == 1 ) template.needTOCRebuild = 1;
}

This section of code describes the individual properties that have been assigned to the context via the Arbortext Styler UI, for all outputs.
Referring to the sample axdocbook.style, for Base (All Outputs), you will see the following settings in the properties area of the Elements list:
Indent category:
Indentation left: 0.00pt
Indentation first line: -0.00pt
The corresponding code fragment is shown below:
block.indent = '-0.00pt';
block.indentStart = '0.00pt';
block.absoluteStart = 0;
Breaks category:
Structure type: Block
The corresponding code fragment is shown below:
formatting.fish[ template.stylerFish ]['isBlock'] = isBlock = 1;
Generated text category:
Numbered element
Added before element content: compound number defined in Division Title Number dialog box
The corresponding code fragment is shown below:
var markerArgs = { followWith : "&#x20;", format : "(PREVIOUS) '.' (CURRENT)", labelPlacement : "beforeNumber", numberStyle : "1", countAs : "title0BA755AB" };
formatting.fish[ template.stylerFish ]['markerType'] = 'Numbering';
if ( !formatting.evaluateXPath( 'x3b2:get-userdata( "_temp_hasbefore_" )' ) != 0 )
{
if ( template.content.getStream('axdocbook_sample:Element:title:title_in_sect1:addBefore') == null )
{
var stream = template.content.createStream( 'axdocbook_sample:Element:title:title_in_sect1:addBefore', fTag.TYPE_EDITOR_TREE );
stream.write( "<?xml version=\"1.0\"?><Gentext xmlns:_dtd=\"\" xmlns:_gte=\"http://www.arbortext.com/namespace/Styler/GeneratedTextElements\" xmlns:_sfe=\"http://www.arbortext.com/namespace/Styler/StylerFormattingElements\" xmlns:_ufe=\"http://www.arbortext.com/namespace/Styler/UserFormattingElements\" xmlns:atidlm=\"http://www.arbortext.com/namespace/atidlm\" xmlns:ch=\"http://www.arbortext.com/namespace/chunker\" xmlns:rtf=\"http://www.cambridgedocs.com/namespace/fo/rtf\" xmlns:saxon=\"http://saxon.sf.net/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><_sfe:BeforeOrAfterText><_gte:LabelAndNumberMarker><_gte:Font><_gte:ElementNumber display=\"#.1\"/></_gte:Font></_gte:LabelAndNumberMarker></_sfe:BeforeOrAfterText></Gentext>" );
}
formatting.evaluateXPath( 'x3b2:clear-before( self::node())' );
formatting.evaluateXPath( 'x3b2:add-before( "axdocbook_sample:Element:title:title_in_sect1:addBefore", 1, self::node())' );
formatting.evaluateXPath( 'x3b2:set-userdata( "_temp_hasbefore_", "1" )' );
var hasTOCEntry = formatting.evaluateXPath( 'x3b2:get-userdata( "app_tocEntry" )' );
if ( hasTOCEntry == 1 ) template.needTOCRebuild = 1;
}

Note that this context is also set to appear in the table of contents for the book (see the table of contents object Book Table of Contents). The last lines in the code reflect this.
Property set information – specific outputs
// processing print/pdf output properties.

template.content.functions[ template.stylerNamespace ].PropertySet['Title_color_for_print']( block );

// processing print/pdf output properties complete.
This section describes a property set that has been assigned to the context for print/PDF outputs only.
Referring to the sample axdocbook.style, for Print/PDF outputs, you will see that the title in sect1 context has the Title color for print property set assigned.
Properties defined via UI – specific outputs
In the sample file, this context has no individual output-specific properties defined for it in the Arbortext Styler UI. There is no information of this type shown in this piece of code. However, if output-specific properties had been defined for the context, these would be listed at this point in the code.
Method for setting column top margin
if ( formatting.fish[ template.stylerFish ]['wantColumnTopMargin'] == 1 )
{
block.marginColumnTop = block.marginTop;
block.marginColumnTopPriority = block.marginTopPriority;
block.vjMarginColumnTop = block.vjMarginTop;
}
else
{
block.marginColumnTop = '0pt';
block.vjMarginColumnTop = '0pt';
}
In this section, a set of if/else conditions describes how the context should be processed based on the settings for it in the Keep space at top of column or page field of the Spacing category in the Arbortext Styler UI. In that field, a setting of Keep equates to a value of 1 in source code, and a setting of Discard will pass a value of 0 in the code. This code fragment specifically describes the formatting that should be applied when the field is set to Keep, and provides an alternative when it is not, i.e. when the Keep space at top of column or page field is set to Discard.
Note that the wantColumnTopMargin variable, as defined at the beginning of the code, is set to hold the Keep space at top of column or page information for the context.
Method for hiding the context in output
var markerType = formatting.fish[ template.stylerFish ]['markerType'];
if ( formatting.fish[ template.stylerFish ]['isHidden'] == 1 )
{
formatting.evaluateXPath( 'x3b2:set-reference( "_app:hidden", 1 )');
useGraphic = false;
if ( markerType != '' )
{
formatting.fish[ template.stylerFish ]['referenceMode'] = '';
if ( markerType == 'Footnote' )
template.content.functions._app[ markerType ]( { attributes: markerArgs } );
else
template.content.functions._app.fom[ markerType ]( markerArgs );
}
return;
}

In this section, a set of if/else conditions describes how to process the context based on the value of the Hidden field of the Text category in the Arbortext Styler UI, including how to deal with markers (bullets, numbering, footnotes) set for the context. In the Hidden field, a setting of Yes equates to a value of 1 in source code, and a setting of No will pass a value of 0 in the code. This code fragment only describes the formatting that should be applied when its value is 1, as otherwise no special action is needed.
Note that the isHidden variable, as defined at the beginning of the code, is set to hold the Hidden information for the context.
Method for starting new pages
var startNew = formatting.fish[ template.stylerFish ]['startNew'];
if ( startNew == '2' )
{
var pageSet = formatting.fish[ template.stylerFish ]['pageSet'];
var pageType = formatting.fish[ template.stylerFish ]['pageType'];
if ( pageSet != '' )
{
template.content.functions[template.stylerNamespace].PageSets[ pageSet ].PageSetup();
if ( block.numColumns == 0 )
{
block.spanColumns = 1;
block.numColumns = formatting.fish[ template.stylerFish ][ 'page_InitialColumns' ];
}

var pageseq = new fDocumentSequenceItem;
pageseq.sequence = template.content.getControl( template.stylerNamespace + ':PageSets:' + pageSet + ':PageSequence' );
pageseq.start = pageType;
pageseq.initial = formatting.fish[ template.stylerFish ]['pageNumber'];
formatting.pageSequenceStart( pageseq, true );
}
else
{
formatting.pageSequenceBreak( Number( pageType ));
}
}
else if ( startNew == '1' )
{
formatting.recordEnd( fFormatting.END_PARAGRAPH, fFormatting.ALIGN_DEFAULT, 1 );
formatting.breakTop( fFormatting.BREAK_COLUMN, 1 );
}

if ( isBlock != -1 ) formatting.fish[ template.stylerFish ]['isBlock'] = isBlock;
if ( formatting.fish[ template.stylerFish ]['isBlock'] == 1 )
{
if ( block.numColumns > 1 )
{
var widths = formatting.fish[ template.stylerFish ][ 'page_'+ block.numColumns + 'Column_Widths' ].split( ',' );
var gutters = formatting.fish[ template.stylerFish ][ 'page_'+ block.numColumns + 'Column_Gutters' ].split( ',' );
for( var i = 0; i < block.numColumns; ++i )
{
block.columns[i].width = widths[i];
block.columns[i].gutter = gutters[i];
}
block.balanceColumns = formatting.fish[ template.stylerFish ][ 'page_BalanceColumns' ] != 0;
}
formatting.blockStart( block );
}
else
{
formatting.styleSave();
formatting.styleChange( style );
formatting.currentParagraph.preserveProperties = 2;
}
In this section, a set of if/else conditions describes how the context should be processed based on the settings made for context in the Start new field on the Breaks category in the Arbortext Styler UI. In the field, a setting of Page equates to a value of 2 in source code, and a setting of Column will pass a value of 1 in the code. This code fragment describes the formatting that should be applied in each of those cases, and provides an alternative if neither of these settings is made. Notice that the code lays out instructions for the start of new page sets, document sequences and number of columns when a new page is started.
Note that the startNew, pageSet, and pageType variables, as defined at the beginning of the code, are set to hold the page start information for the context.
Method for creating a new block
if ( isBlock != -1 ) formatting.fish[ template.stylerFish ]['isBlock'] = isBlock;
if ( formatting.fish[ template.stylerFish ]['isBlock'] == 1 )
{
if ( block.numColumns > 1 )
{
var widths = formatting.fish[ template.stylerFish ][ 'page_'+ block.numColumns + 'Column_Widths' ].split( ',' );
var gutters = formatting.fish[ template.stylerFish ][ 'page_'+ block.numColumns + 'Column_Gutters' ].split( ',' );
for( var i = 0; i < block.numColumns; ++i )
{
block.columns[i].width = widths[i];
block.columns[i].gutter = gutters[i];
}
block.balanceColumns = formatting.fish[ template.stylerFish ][ 'page_BalanceColumns' ] != 0;
}
formatting.blockStart( block );
}
else
{
formatting.styleSave();
formatting.styleChange( style );
formatting.currentParagraph.preserveProperties = 2;
}
In this section, a set of if/else conditions describes how the context should be processed based on the settings made for context in the Structure type field on the Breaks category in the Arbortext Styler UI. In the field, a setting of Block equates to a value of 1 in source code. This code fragment specifically describes the formatting that should be applied when the structure is set to Block, and provide an alternative when it is not, i.e. when the Structure type field is set to Inline. Notice that the code lays out instructions for creation of individual columns and gutters when the context is of Block structure. This aligns with the column information provided in the page set for the context – you can therefore chose to edit the column information in either the code or the page set.
Note that the isBlock variable, as defined at the beginning of the code, is set to hold the Structure type information for the context.
Method for including context in table of contents
formatting.formatStream( template.content.streams._app.Reference );
template.content.functions._app.MakeLink( { attributes : { forTOC : "true", inPDF : "true", level : 2, formatStream : template.stylerNamespace + ":TOCs:Book_Table_of_Contents:title_in_sect1" }} );
This section reflects the settings made in the stylesheet for the context, for its appearance in a table of contents. Here you can see that the title in sect1 context is selected for inclusion at level 2 of a table of contents generated by the Book Table of Contents table of contents object. For confirmation of these settings, please refer to Book Table of Contents object in the Table of Contents list in the Arbortext Styler UI.
Method for setting markers
if ( markerType != '' )
{
formatting.fish[ template.stylerFish ]['referenceMode'] = '';
if ( markerType == 'Footnote' )
template.content.functions._app[ markerType ]( { attributes: markerArgs } );
else
template.content.functions._app.fom[ markerType ]( markerArgs );
}
In this section, a set of if/else conditions describes how to process any markers (bullets, numbers, footnotes) set for the context.
Note that the markerType variable, as defined at the beginning of the code, is set to hold the marker information for the context.
Method for outputting graphics
if ( useGraphic ) template.content.functions._app.Graphic( { attributes: graphic } );
This section states that if a context contains a graphic, one will be output.
Note that the useGraphic variable, as defined at the beginning of the code, is set hold the graphic information for the context.
Context contents
This section describes objects that are contained within the boundary of the selected context, for example a table or a definition list within a block. There is no information of this type shown in this piece of code so the entry is empty.
OnExit command
<OnExit type=”application/x-javascript” xml:space=”preserve”>

<![CDATA[ // onExit processing for context: sect1/title

if ( formatting.fish[ template.stylerFish ]['markerType'] != '' && formatting.fish[ template.stylerFish ]['markerType'] != 'Footnote' )
{
template.content.functions._app.fom[ 'end'+formatting.fish[ template.stylerFish ]['markerType']]();
}

switch ( formatting.fish[ template.stylerFish ]['isBlock'] )
{
case '1': formatting.endBlock( 2 ); break;
case '-1': break;
case '0':
default:
formatting.styleRestore(); break;
break;
}

if ( formatting.fish[ template.stylerFish ]['startNew'] != 0 && formatting.fish[ template.stylerFish ]['pageSet'] != '' )
{
formatting.pageSequenceEnd( true );
formatting.output( '<?breakt 2,2>' );
}

formatting.fishRestore( template.stylerFish );
]]></OnExit>
The OnExit command marks the end of the context. It contains instructions to undo everything set by the OnEnter command – ends the object that was created, terminates any page sequencing, resets variables, etc.