IntroductionRich Text Format (RTF) is a specification used by common word processing applications, such as Microsoft Word. When you save a document, RTF is a file type option that you select. Show
BI Publisher's RTF Template Parser converts documents saved as the RTF file type to XSL-FO. You can therefore create report designs using many of your standard word processing application's design features and BI Publisher will recognize and maintain the design. During design time, you add data fields and other markup to your template using BI Publisher's simplified tags for XSL expressions. These tags associate the XML report data to your report layout. If you are familiar with XSL and prefer not to use the simplified tags, BI Publisher also supports the use of pure XSL elements in the template. In addition to your word processing application's formatting features, BI Publisher supports other advanced reporting features such as conditional formatting, dynamic data columns, running totals, and charts. If you wish to include code directly in your template, you can include any XSL element, many FO elements, and a set of SQL expressions extended by BI Publisher. Supported ModesBI Publisher supports two methods for creating RTF templates:
This guide describes how to create RTF templates using both methods. PrerequisitesBefore you design your template, you must:
OverviewCreating an RTF template file consists of two basic steps:
When you design your template layout, you must understand how to associate the XML input file to the layout. This chapter presents a sample template layout with its input XML file to illustrate how to make the proper associations to add the markup tags to the template. Using the BI Publisher Template BuilderThe Template Builder is an extension to Microsoft Word that simplifies the development of RTF templates. It automates many of the manual steps that are covered in this chapter. Use it in conjunction with this manual to increase your productivity. The Template Builder is tightly integrated with Microsoft Word and allows you to perform the following functions:
Manual steps for performing these functions are covered in this chapter. Instructions and tutorials for using the Template Builder are available from the readme and help files delivered with the tool. Associating the XML Data to the Template LayoutThe following is a sample layout for a Payables Invoice Register: Sample Template Layout Note the following:
XML Input FileFollowing is the XML file that will be used as input to the Payables Invoice Register report template: Note: To simplify the example, the XML output shown below has been modified from the actual output from the Payables report. <?xml version="1.0" encoding="WINDOWS-1252" ?> - <VENDOR_REPORT> - <LIST_G_VENDOR_NAME> - <G_VENDOR_NAME> <VENDOR_NAME>COMPANY A</VENDOR_NAME> - <LIST_G_INVOICE_NUM> - <G_INVOICE_NUM> <SET_OF_BOOKS_ID>124</SET_OF_BOOKS_ID> <GL_DATE>10-NOV-03</GL_DATE> <INV_TYPE>Standard</INV_TYPE> <INVOICE_NUM>031110</INVOICE_NUM> <INVOICE_DATE>10-NOV-03</INVOICE_DATE> <INVOICE_CURRENCY_CODE>EUR</INVOICE_CURRENCY_CODE> <ENT_AMT>122</ENT_AMT> <ACCTD_AMT>122</ACCTD_AMT> <VAT_CODE>VAT22%</VAT_CODE> </G_INVOICE_NUM> </LIST_G_INVOICE_NUM> <ENT_SUM_VENDOR>1000.00</ENT_SUM_VENDOR> <ACCTD_SUM_VENDOR>1000.00</ACCTD_SUM_VENDOR> </G_VENDOR_NAME> </LIST_G_VENDOR_NAME> <ACCTD_SUM_REP>108763.68</ACCTD_SUM_REP> <ENT_SUM_REP>122039</ENT_SUM_REP> </VENDOR_REPORT> XML files are composed of elements. Each tag set is an element. For example <INVOICE_DATE> </INVOICE_DATE> is the invoice date element. "INVOICE_DATE" is the tag name. The data between the tags is the value of the element. For example, the value of INVOICE_DATE is "10-NOV-03". The elements of the XML file have a hierarchical structure. Another way of saying this is that the elements have parent-child relationships. In the XML sample, some elements are contained within the tags of another element. The containing element is the parent and the included elements are its children. Every XML file has only one root element that contains all the other elements. In this example, VENDOR_REPORT is the root element. The elements LIST_G_VENDOR_NAME, ACCTD_SUM_REP, and ENT_SUM_REP are contained between the VENDOR_REPORT tags and are children of VENDOR_REPORT. Each child element can have child elements of its own. Identifying Placeholders and GroupsYour template content and layout must correspond to the content and hierarchy of the input XML file. Each data field in your template must map to an element in the XML file. Each group of repeating elements in your template must correspond to a parent-child relationship in the XML file. To map the data fields you define placeholders. To designate the repeating elements, you define groups. Note: BI Publisher supports regrouping of data if your report requires grouping that does not follow the hierarchy of your incoming XML data. For information on using this feature, see Regrouping the XML Data. PlaceholdersEach data field in your report template must correspond to an element in the XML file. When you mark up your template design, you define placeholders for the XML elements. The placeholder maps the template report field to the XML element. At runtime the placeholder is replaced by the value of the element of the same name in the XML data file. For example, the "Supplier" field from the sample report layout corresponds to the XML element VENDOR_NAME. When you mark up your template, you create a placeholder for VENDOR_NAME in the position of the Supplier field. At runtime, this placeholder will be replaced by the value of the element from the XML file (the value in the sample file is COMPANY A). Identifying the Groups of Repeating ElementsThe sample report lists suppliers and their invoices. There are fields that repeat for each supplier. One of these fields is the supplier's invoices. There are fields that repeat for each invoice. The report therefore consists of two groups of repeating fields:
The invoices group is nested inside the suppliers group. This can be represented as follows: Suppliers
Compare this structure to the hierarchy of the XML input file. The fields that belong to the Suppliers group shown above are children of the element G_VENDOR_NAME. The fields that belong to the Invoices group are children of the element G_INVOICE_NUM. By defining a group, you are notifying BI Publisher that for each occurrence of an element (parent), you want the included fields (children) displayed. At runtime, BI Publisher will loop through the occurrences of the element and display the fields each time. Designing the Template LayoutUse your word processing application's formatting features to create the design. For example:
For a detailed list of supported formatting features in Microsoft Word, see Supported Native Formatting Features. Additional formatting and reporting features are described at the end of this section. Adding Markup to the Template LayoutBI Publisher converts the formatting that you apply in your word processing application to XSL-FO. You add markup to create the mapping between your layout and the XML file and to include features that cannot be represented directly in your format. The most basic markup elements are placeholders, to define the XML data elements; and groups, to define the repeating elements. BI Publisher provides tags to add markup to your template. Note: For the XSL equivalents of the BI Publisher tags, see XSL Equivalent Syntax. Creating PlaceholdersThe placeholder maps the template field to the XML element data field. At runtime the placeholder is replaced by the value of the element of the same name in the XML data file. Enter placeholders in your document using the following syntax: <?XML element tag name?> Note: The placeholder must match the XML element tag name exactly. It is case sensitive. There are two ways to insert placeholders in your document:
Basic RTF MethodEnter the placeholder syntax in your document where you want the XML data value to appear. Enter the element's XML tag name using the syntax: <?XML element tag name?> In the example, the template field "Supplier" maps to the XML element VENDOR_NAME. In your document, enter: <?VENDOR_NAME?> The entry in the template is shown in the following figure: Form Field MethodUse Microsoft Word's Text Form Field Options window to insert the placeholder tags:
Complete the ExampleThe following table shows the entries made to complete the example. The Template Field Name is the display name from the template. The Default Text Entry is the value entered in the Default Text field of the Text Form Field Options dialog box (form field method only). The Placeholder Entry is the XML element tag name entered either in the Form Field Help Text field (form field method) or directly on the template.
The following figure shows the Payables Invoice Register with the completed form field placeholder markup. See the Payables Invoice Register with Completed Basic RTF Markup for the completed basic RTF markup. Defining GroupsBy defining a group, you are notifying BI Publisher that for each occurrence of an element, you want the included fields displayed. At runtime, BI Publisher will loop through the occurrences of the element and display the fields each time. In the example, for each occurrence of G_VENDOR_NAME in the XML file, we want the template to display its child elements VENDOR_NAME (Supplier Name), G_INVOICE_NUM (the Invoices group), Total Entered Amount, and Total Accounted Amount. And, for each occurrence of G_INVOICE_NUM (Invoices group), we want the template to display Invoice Number, Invoice Date, GL Date, Currency, Entered Amount, and Accounted Amount. To designate a group of repeating fields, insert the grouping tags around the elements to repeat. Insert the following tag before the first element: <?for-each:XML group element tag name?> Insert the following tag after the final element: <?end for-each?> Grouping scenariosNote that the group element must be a parent of the repeating elements in the XML input file.
Basic RTF MethodEnter the tags in your document to define the beginning and end of the repeating element group. To create the Suppliers group in the example, insert the tag <?for-each:G_VENDOR_NAME?> before the Supplier field that you previously created. Insert <?end for-each?> in the document after the summary row. The following figure shows the Payables Invoice Register with the basic RTF grouping and placeholder markup: Form Field Method
Complete the ExampleThe second group in the example is the invoices group. The repeating elements in this group are displayed in the table. For each invoice, the table row should repeat. Create a group within the table to contain these elements. Note: For each invoice, only the table row should repeat, not the entire table. Placing the grouping tags at the beginning and end of the table row will repeat only the row. If you place the tags around the table, then for each new invoice the entire table with headings will be repeated. To mark up the example, insert the grouping tag <?for-each:G_INVOICE_NUM?> in the table cell before the Invoice Num placeholder. Enter the Default text "Group:Invoices" to designate the beginning of the group. Insert the end tag inside the final table cell of the row after the Accounted Amt placeholder. Enter the Default text "End:Invoices" to designate the end of the group. The following figure shows the completed example using the form field method: Defining Headers and FootersNative SupportBI Publisher supports the use of the native RTF header and footer feature. To create a header or footer, use the your word processing application's header and footer insertion tools. As an alternative, or if you have multiple headers and footers, you can use start:body and end body tags to distinguish the header and footer regions from the body of your report. Inserting Placeholders in the Header and FooterAt the time of this writing, Microsoft Word does not support form fields in the header and footer. You must therefore insert the placeholder syntax directly into the template (basic RTF method), or use the start body/end body syntax described in the next section. Multiple or Complex Headers and FootersIf your template requires multiple headers and footers, create them by using BI Publisher tags to define the body area of your report. You may also want to use this method if your header and footer contain complex objects that you wish to place in form fields. When you define the body area, the elements occurring before the beginning of the body area will compose the header. The elements occurring after the body area will compose the footer. Use the following tags to enclose the body area of your report: <?start:body?> <?end body?> Use the tags either directly in the template, or in form fields. The Payables Invoice Register contains a simple header and footer and therefore does not require the start body/end body tags. However, if you wanted to add another header to the template, define the body area as follows:
The following figure shows the Payables Invoice Register with the start body/end body tags inserted: Different First Page and Different Odd and Even Page SupportIf your report requires a different header and footer on the first page of your report; or, if your report requires different headers and footers for odd and even pages, you can define this behavior using Microsoft Word's Page Setup dialog.
At runtime your generated report will exhibit the defined header and footer behavior. Inserting Images and ChartsImagesBI Publisher supports several methods for including images in your published document: Direct InsertionInsert the jpg, gif, or png image directly in your template. URL ReferenceURL Reference
Element Reference from XML File
Rendering an Image Retrieved from BLOB DataIf your data source is a Data Template (for information, see Data Templates) and your results XML contains image data that had been stored as a BLOB in the database, use the following syntax in a form field inserted in your template where you want the image to render at runtime: <fo:instream-foreign-object content type="image/jpg"> <xsl:value-of select="IMAGE_ELEMENT"/> </fo:instream-foreign-object> where image/jpg is the MIME type of the image (other options might be: image/gif and image/png) and IMAGE_ELEMENT is the element name of the BLOB in your XML data. Note that you can specify height and width attributes for the image to set its size in the published report. BI Publisher will scale the image to fit the box size that you define. For example, to set the size of the example above to three inches by four inches, enter the following: <fo:instream-foreign-object content type="image/jpg" height="3 in" width="4 in"> <xsl:value-of select="IMAGE_ELEMENT"/> </fo:instream-foreign-object> Specify in pixels as follows: <fo:instream-foreign-object content type="image/jpg" height="300 px" width="4 px"> ... or in centimeters: <fo:instream-foreign-object content type="image/jpg" height="3 cm" width="4 cm"> ... or as a percentage of the original dimensions: <fo:instream-foreign-object content type="image/jpg" height="300%" width="300%"> ... Chart SupportBI Publisher leverages the graph capabilities of Oracle Business Intelligence Beans (BI Beans) to enable you to define charts and graphs in your RTF templates that will be populated with data at runtime. BI Publisher supports all the graph types and component attributes available from the BI Beans graph DTD. The BI Beans graph DTD is fully documented in the following technical note available from the Oracle Technology Network (OTN): "DTD for Customizing Graphs in Oracle Reports." The following summarizes the steps to add a chart to your template. These steps will be discussed in detail in the example that follows:
Adding a Sample ChartFollowing is a piece of XML data showing total sales by company division. <sales year=2004> <division> <name>Groceries</name> <totalsales>3810</totalsales> <costofsales>2100</costofsales> </division> <division> <name>Toys</name> <totalsales>2432</totalsales> <costofsales>1200</costofsales> </division> <division> <name>Cars</name> <totalsales>6753</totalsales> <costofsales>4100</costofsales> </division> <division> <name>Hardware</name> <totalsales>2543</totalsales> <costofsales>1400</costofsales> </division> <division> <name>Electronics</name> <totalsales>5965</totalsales> <costofsales>3560</costofsales> </division> </sales> This example will show how to insert a chart into your template to display it as a vertical bar chart as shown in the following figure: Note the following attributes of this chart:
Each of these properties can be customized to suit individual report requirements. Inserting the Dummy ImageThe first step is to add a dummy image to the template in the position you want the chart to appear. The image size will define how big the chart image will be in the final document. Important: You must insert the dummy image as a "Picture" and not any other kind of object. The following figure shows an example of a dummy image: The image can be embedded inside a for-each loop like any other form field if you want the chart to be repeated in the output based on the repeating data. In this example, the chart is defined within the sales year group so that a chart will be generated for each year of data present in the XML file. Right-click the image to open the Format Picture palette and select the Web tab. Use the Alternative text entry box to enter the code to define the chart characteristics and data definition for the chart. Adding Code to the Alternative Text BoxThe following graphic shows an example of the BI Publisher code in the Format Picture Alternative text box: The content of the Alternative text represents the chart that will be rendered in the final document. For this chart, the text is as follows: chart: <Graph graphType = "BAR_VERT_CLUST"> <Title text="Company Sales 2004" visible="true" horizontalAlignment="CENTER"/> <Y1Title text="Sales in Thousands" visible="true"/> <O1Title text="Division" visible="true"/> <LocalGridData colCount="{count(//division)}" rowCount="1"> <RowLabels> <Label>Total Sales $1000s</Label> </RowLabels> <ColLabels> <xsl:for-each select="//division"> <Label> <xsl:value-of select="name"/> </Label> </xsl:for-each> </ColLabels> <DataValues> <RowData> <xsl:for-each select="//division"> <Cell> <xsl:value-of select="totalsales"/> </Cell> </xsl:for-each> </RowData> </DataValues> </LocalGridData> </Graph> The first element of your chart text must be the chart: element to inform the RTF parser that the following code describes a chart object. Next is the opening <Graph> tag. Note that the whole of the code resides within the tags of the <Graph> element. This element has an attribute to define the chart type: graphType. If this attribute is not declared, the default chart is a vertical bar chart. BI Beans supports many different chart types. Several more types are presented in this section. For a complete listing, see the BI Beans graph DTD documentation. The following code section defines the chart type and attributes: <Title text="Company Sales 2004" visible="true" horizontalAlignment="CENTER"/> <Y1Title text="Sales in Thousands" visible="true"/> <O1Title text="Division" visible="true"/> All of these values can be declared or you can substitute values from the XML data at runtime. For example, you can retrieve the chart title from an XML tag by using the following syntax: <Title text="{CHARTTITLE}" visible="true" horizontalAlighment="CENTER"/> where "CHARTTITLE" is the XML tag name that contains the chart title. Note that the tag name is enclosed in curly braces. The next section defines the column and row labels: <LocalGridData colCount="{count(//division)}" rowCount="1"> <RowLabels> <Label>Total Sales $1000s</Label> </RowLabels> <ColLabels> <xsl:for-each select="//division"> <Label> <xsl:value-of select="name"/> </Label> </xsl:for-each> </ColLabels> The LocalGridData element has two attributes: colCount and rowCount. These define the number of columns and rows that will be shown at runtime. In this example, a count function calculates the number of columns to render: colCount="{count(//division)}" The rowCount has been hard-coded to 1. This value defines the number of sets of data to be charted. In this case it is 1. Next the code defines the row and column labels. These can be declared, or a value from the XML data can be substituted at runtime. The row label will be used in the chart legend (that is, "Total Sales $1000s"). The column labels for this example are derived from the data: Groceries, Toys, Cars, and so on. This is done using a for-each loop: <ColLabels> <xsl:for-each select="//division"> <Label> <xsl:value-of select="name"/> </Label> </xsl:for-each> </ColLabels> This code loops through the <division> group and inserts the value of the <name> element into the <Label> tag. At runtime, this will generate the following XML: <ColLabels> <Label>Groceries</Label> <Label>Toys</Label> <Label>Cars</Label> <Label>Hardware</Label> <Label>Electronics</Label> </ColLabels> The next section defines the actual data values to chart: <DataValues> <RowData> <xsl:for-each select="//division"> <Cell> <xsl:value-of select="totalsales"/> </Cell> </xsl:for-each> </RowData> </DataValues> Similar to the labels section, the code loops through the data to build the XML that is passed to the BI Beans rendering engine. This will generate the following XML: <DataValues> <RowData> <Cell>3810</Cell> <Cell>2432</Cell> <Cell>6753</Cell> <Cell>2543</Cell> <Cell>5965</Cell> </RowData> </DataValues> Additional Chart SamplesYou can also display this data in a pie chart as shown in the following figure: The following is the code added to the template to render this chart at runtime: chart: <Graph graphType="PIE"> <Title text="Company Sales 2004" visible="true" horizontalAlignment="CENTER"/> <LocalGridData rowCount="{count(//division)}" colCount="1"> <RowLabels> <xsl:for-each select="//division"> <Label> <xsl:value-of select="name"/> </Label> </xsl:for-each> </RowLabels> <DataValues> <xsl:for-each select="//division"> <RowData> <Cell> <xsl:value-of select="totalsales"/> </Cell> </RowData> </xsl:for-each> </DataValues> </LocalGridData> </Graph> Horizontal Bar Chart SampleThe following example shows total sales and cost of sales charted in a horizontal bar format. This example also adds the data from the cost of sales element (<costofsales>) to the chart: The following code defines this chart in the template: chart: <Graph graphType = "BAR_HORIZ_CLUST"> <Title text="Company Sales 2004" visible="true" horizontalAlignment="CENTER"/> <LocalGridData colCount="{count(//division)}" rowCount="2"> <RowLabels> <Label>Total Sales ('000s)</Label> <Label>Cost of Sales ('000s)</Label> </RowLabels> <ColLabels> <xsl:for-each select="//division"> <Label><xsl:value-of select="name"/></Label> </xsl:for-each> </ColLabels> <DataValues> <RowData> <xsl:for-each select="//division"> <Cell><xsl:value-of select="totalsales"/></Cell> </xsl:for-each> </RowData> <RowData> <xsl:for-each select="//division"> <Cell><xsl:value-of select="costofsales"/></Cell> </xsl:for-each> </RowData> </DataValues> </LocalGridData> </Graph> To accommodate the second set of data, the rowCount attribute for the LocalGridData element is set to 2. Also note the DataValues section defines two sets of data: one for Total Sales and one for Cost of Sales. Changing the Appearance of Your ChartThere are many attributes available from the BI Beans graph DTD that you can manipulate to change the look and feel of your chart. For example, the previous chart can be changed to remove the grid, place a graduated background, and change the bar colors and fonts as shown in the following figure: The code to support this is as follows: chart: <Graph graphType = "BAR_HORIZ_CLUST"> <SeriesItems> <Series id="0" color="#ffcc00"/> <Series id="1" color="#ff6600"/> </SeriesItems> <O1MajorTick visible="false"/> <X1MajorTick visible="false"/> <Y1MajorTick visible="false"/> <Y2MajorTick visible="false"/> <MarkerText visible="true" markerTextPlace="MTP_CENTER"/> <PlotArea borderTransparent="true"> <SFX fillType="FT_GRADIENT" gradientDirection="GD_LEFT" gradientNumPins="300"> <GradientPinStyle pinIndex="1" position="1" gradientPinLeftColor="#999999" gradientPinRightColor="#cc6600"/> </SFX> </PlotArea> <Title text="Company Sales 2004" visible="true"> <GraphFont name="Tahoma" bold="false"/> </Title> . . . </Graph> The colors for the bars are defined in the SeriesItems section. The colors are defined in hexadecimal format as follows: <SeriesItems> <Series id="0" color="#ffcc00"/> <Series id="1" color="#ff6600"/> </SeriesItems> The following code hides the chart grid: <O1MajorTick visible="false"/> <X1MajorTick visible="false"/> <Y1MajorTick visible="false"/> <Y2MajorTick visible="false"/> The MarkerText tag places the data values on the chart bars: <MarkerText visible="true" markerTextPlace="MTP_CENTER"/> The PlotArea section defines the background. The SFX element establishes the gradient and the borderTransparent attribute hides the plot border: <PlotArea borderTransparent="true"> <SFX fillType="FT_GRADIENT" gradientDirection="GD_LEFT" gradientNumPins="300"> <GradientPinStyle pinIndex="1" position="1" gradientPinLeftColor="#999999" gradientPinRightColor="#cc6600"/> </SFX> </PlotArea> The Title text tag has also been updated to specify a new font type and size: <Title text="Company Sales 2004" visible="true"> <GraphFont name="Tahoma" bold="false"/> </Title> Drawing, Shape, and Clip Art SupportBI Publisher supports Microsoft Word drawing, shape, and clip art features. You can add these objects to your template and they will be rendered in your final PDF output. The following AutoShape categories are supported:
Freehand DrawingUse the freehand drawing tool in Microsoft Word to create drawings in your template to be rendered in the final PDF output. HyperlinksYou can add hyperlinks to your shapes. See Hyperlinks. LayeringYou can layer shapes on top of each other and use the transparency setting in Microsoft Word to allows shapes on lower layers to show through. The following graphic shows an example of layered shapes: 3-D EffectsBI Publisher does not currently support the 3-D option for shapes. Microsoft EquationUse the equation editor to generate equations in your output. The following figure shows an example of an equation: Organization ChartUse the organization chart functionality in your templates and the chart will be rendered in the output. The following image shows an example of an organization chart: WordArtYou can use Microsoft Word's WordArt functionality in your templates. The following graphic shows a WordArt example: Note: Some Microsoft WordArt uses a bitmap operation that currently cannot be converted to SVG. To use the unsupported WordArt in your template, you can take a screenshot of the WordArt then save it as an image (gif, jpeg, or png) and replace the WordArt with the image. Data Driven Shape SupportIn addition to supporting the static shapes and features in your templates, BI Publisher supports the manipulation of shapes based on incoming data or parameters, as well. The following manipulations are supported:
These manipulations not only apply to single shapes, but you can use the group feature in Microsoft Word to combine shapes together and manipulate them as a group. Placement of CommandsEnter manipulation commands for a shape in the Web tab of the shape's properties dialog as shown in the following example figure: Replicate a ShapeYou can replicate a shape based on incoming XML data in the same way you replicate data elements in a for-each loop. To do this, use a for-each@shape command in conjunction with a shape-offset declaration. For example, to replicate a shape down the page, use the following syntax: <?for-each@shape:SHAPE_GROUP?> <?shape-offset-y:(position()-1)*100?> <?end for-each?> where for-each@shape opens the for-each loop for the shape context SHAPE_GROUP is the name of the repeating element from the XML file. For each occurrence of the element SHAPE_GROUP a new shape will be created. shape-offset-y: - is the command to offset the shape along the y-axis. (position()-1)*100) - sets the offset in pixels per occurrence. The XSL position command returns the record counter in the group (that is 1,2,3,4); one is subtracted from that number and the result is multiplied by 100. Therefore for the first occurrence the offset would be 0: (1-1) * 100. The offset for the second occurrence would be 100 pixels: (2-1) *100. And for each subsequent occurrence the offset would be another 100 pixels down the page. Add Text to a ShapeYou can add text to a shape dynamically either from the incoming XML data or from a parameter value. In the property dialog enter the following syntax: <?shape-text:SHAPETEXT?> where SHAPETEXT is the element name in the XML data. At runtime the text will be inserted into the shape. Add Text Along a PathYou can add text along a line or curve from incoming XML data or a parameter. After drawing the line, in the property dialog enter: <?shape-text-along-path:SHAPETEXT?> where SHAPETEXT is the element from the XML data. At runtime the value of the element SHAPETEXT will be inserted above and along the line. Moving a ShapeYou can move a shape or transpose it along both the x and y-axes based on the XML data. For example to move a shape 200 pixels along the y-axis and 300 along the x-axis, enter the following commands in the property dialog of the shape: <?shape-offset-x:300?> <?shape-offset-y:200?> Rotating a ShapeTo rotate a shape about a specified axis based on the incoming data, use the following command: <?shape-rotate:ANGLE;'POSITION'?> where ANGLE is the number of degrees to rotate the shape. If the angle is positive, the rotation is clockwise; if negative, the rotation is counterclockwise. POSITION is the point about which to carry out the rotation, for example, 'left/top'. Valid values are combinations of left, right, or center with center, top, or bottom. The default is left/top. The following figure shows these valid values: To rotate this rectangle shape about the bottom right corner, enter the following syntax: <?shape-rotate:60,'right/bottom'?> You can also specify an x,y coordinate within the shape itself about which to rotate. Skewing a ShapeYou can skew a shape along its x or y axis using the following commands: <?shape-skew-x:ANGLE;'POSITION'?> <?shape-skew-y:ANGLE;'POSITION'?> where ANGLE is the number of degrees to skew the shape. If the angle is positive, the skew is to the right. POSITION is the point about which to carry out the rotation, for example, 'left/top'. Valid values are combinations of left, right, or center with center, top, or bottom. See the figure under Rotating a Shape. The default is 'left/top'. For example, to skew a shape by 30 degrees about the bottom right hand corner, enter the following: <?shape-skew-x:number(.)*30;'right/bottom'?> Changing the Size of a ShapeYou can change the size of a shape using the appropriate commands either along a single axis or both axes. To change a shape's size along both axes, use: <?shape-size:RATIO?> where RATIO is the numeric ratio to increase or decrease the size of the shape. Therefore a value of 2 would generate a shape twice the height and width of the original. A value of 0.5 would generate a shape half the size of the original. To change a shape's size along the x or y axis, use: <?shape-size-x:RATIO?> <?shape-size-y:RATIO?> Changing only the x or y value has the effect of stretching or shrinking the shape along an axis. This can be data driven. Combining CommandsYou can also combine these commands to carry out multiple transformations on a shape at one time. For example, you can replicate a shape and for each replication, rotate it by some angle and change the size at the same time. The following example shows how to replicate a shape, move it 50 pixels down the page, rotate it by five degrees about the center, stretch it along the x-axis and add the number of the shape as text: <for-each@shape:SHAPE_GROUP?> <?shape-text:position()?> <?shape-offset-y:position()*50?> <?shape-rotate:5;'center/center'?> <?shape-size-x:position()+1?> <end for-each?> This would generate the output shown in the following figure: CD Ratings ExampleThis example demonstrates how to set up a template that will generate a star-rating based on data from an incoming XML file. Assume the following incoming XML data: <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> <USER_RATING>4</USER_RATING> </CD> <CD> <TITLE>Hide Your Heart</TITLE> <ARTIST>Bonnie Tylor</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> <USER_RATING>3</USER_RATING> </CD> <CD> <TITLE>Still got the blues</TITLE> <ARTIST>Gary More</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin Records</COMPANY> <PRICE>10.20</PRICE> <YEAR>1990</YEAR> <USER_RATING>5</USER_RATING> </CD> <CD> <TITLE>This is US</TITLE> <ARTIST>Gary Lee</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin Records</COMPANY> <PRICE>12.20</PRICE> <YEAR>1990</YEAR> <USER_RATING>2</USER_RATING> </CD> <CATALOG> Notice there is a USER_RATING element for each CD. Using this data element and the shape manipulation commands, we can create a visual representation of the ratings so that the reader can compare them at a glance. A template to achieve this is shown in the following figure: The values for the fields are shown in the following table:
The form fields hold the simple element values. The only difference with this template is the value for the star shape. The replication command is placed in the Web tab of the Format AutoShape dialog. In the for-each@shape command we are using a command to create a "for...next loop" construct. We specify 1 as the starting number; the value of USER_RATING as the final number; and 1 as the step value. As the template loops through the CDs, we create an inner loop to repeat a star shape for every USER_RATING value (that is, a value of 4 will generate 4 stars). The output from this template and the XML sample is shown in the following graphic: Grouped Shape ExampleThis example shows how to combine shapes into a group and have them react to the incoming data both individually and as a group. Assume the following XML data: <SALES> <SALE> <REGION>Americas</REGION> <SOFTWARE>1200</SOFTWARE> <HARDWARE>850</HARDWARE> <SERVICES>2000</SERVICES> </SALE> <SALE> <REGION>EMEA</REGION> <SOFTWARE>1000</SOFTWARE> <HARDWARE>800</HARDWARE> <SERVICES>1100</SERVICES> </SALE> <SALE> <REGION>APAC</REGION> <SOFTWARE>900</SOFTWARE> <HARDWARE>1200</HARDWARE> <SERVICES>1500</SERVICES> </SALE> </SALES> You can create a visual representation of this data so that users can very quickly understand the sales data across all regions. Do this by first creating the composite shape in Microsoft Word that you wish to manipulate. The following figure shows a composite shape made up of four components: The shape consists of three cylinders: red, yellow, and blue. These will represent the data elements software, hardware, and services. The combined object also contains a rectangle that is enabled to receive text from the incoming data. The following commands are entered into the Web tab: Red cylinder: <?shape-size-y:SOFTWARE div 1000;'left/bottom'?> Yellow cylinder: <?shape-size-y:HARDWARE div 1000;'left/bottom'?> Blue cylinder: <?shape-size-y:SERVICES div 1000;'left/bottom'?> The shape-size command is used to stretch or shrink the cylinder based on the values of the elements SOFTWARE, HARDWARE, and SERVICES. The value is divided by 1000 to set the stretch or shrink factor. For example, if the value is 2000, divide that by 1000 to get a factor of 2. The shape will generate as twice its current height. The text-enabled rectangle contains the following command in its Web tab: <?shape-text:REGION?> At runtime the value of the REGION element will appear in the rectangle. All of these shapes were then grouped together and in the Web tab for the grouped object, the following syntax is added: <?for-each@shape:SALE?> <?shape-offset-x:(position()-1)*110?> <?end for-each?> In this set of commands, the for-each@shape loops over the SALE group. The shape-offset command moves the next shape in the loop to the right by a specific number of pixels. The expression (position()-1) sets the position of the object. The position() function returns a record counter while in the loop, so for the first shape, the offset would be 1-1*100, or 0, which would place the first rendering of the object in the position defined in the template. Subsequent occurrences would be rendered at a 100 pixel offset along the x-axis (to the right). At runtime three sets of shapes will be rendered across the page as shown in the following figure: To make an even more visually representative report, these shapes can be superimposed onto a world map. Just use the "Order" dialog in Microsoft Word to layer the map behind the grouped shapes. Microsoft Word 2000 Users: After you add the background map and overlay the shape group, use the Grouping dialog to make the entire composition one group. Microsoft Word 2002/3 Users: These versions of Word have an option under Tools > Options, General tab to "Automatically generate drawing canvas when inserting autoshapes". Using this option removes the need to do the final grouping of the map and shapes. We can now generate a visually appealing output for our report as seen in the following figure: Supported Native Formatting FeaturesIn addition to the features already listed, BI Publisher supports the following features of Microsoft Word. General Features
AlignmentUse your word processor's alignment features to align text, graphics, objects, and tables. Note: Bidirectional languages are handled automatically using your word processing application's left/right alignment controls. TablesSupported table features include:
An example of truncation is shown in the following graphic: Date FieldsInsert dates using the date feature of your word processing application. Note that this date will correspond to the publishing date, not the request run date. Multicolumn Page SupportBI Publisher supports Microsoft Word's Columns function to enable you to publish your output in multiple columns on a page. Select Format > Columns to display the Columns dialog box to define the number of columns for your template. The following graphic shows the Columns dialog: Multicolumn Page Example: Labels To generate address labels in a two-column format:
Tip: To prevent the address block from breaking across pages or columns, embed the label block inside a single-celled table. Then specify in the Table Properties that the row should not break across pages. See Prevent rows from breaking across pages. This template will produce the following multicolumn output: Background and Watermark SupportBI Publisher supports the "Background" feature in Microsoft Word. You can specify a single, graduated color or an image background for your template to be displayed in the PDF output. Note that this feature is supported for PDF output only. To add a background to your template, use the Format > Background menu option. Add a Background Using Microsoft Word 2000From the Background pop up menu, you can:
Add a Text or Image Watermark Using Microsoft Word 2002 or laterThese versions of Microsoft Word allow you to add either a text or image watermark. Use the Format > Background > Printed Watermark dialog to select either:
Template FeaturesPage BreaksTo create a page break after the occurrence of a specific element use the "split-by-page-break" alias. This will cause the report output to insert a hard page break between every instance of a specific element. To insert a page break between each occurrence of a group, insert the "split-by-page-break" form field within the group immediately before the <?end for-each?> tag that closes the group. In the Help Text of this form field enter the syntax: <?split-by-page-break:?> For the following XML, assume you want to create a page break for each new supplier: <SUPPLIER> <NAME>My Supplier</NAME> <INVOICES> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>1-Jan-2005</INVDATE> <INVAMT>100</INVOICEAMT> </INVOICE> <INVOICE> <INVNUM>10001-2</INVNUM> <INVDATE>10-Jan-2005</INVDATE> <INVAMT>200</INVOICEAMT> </INVOICE> </INVOICES> </SUPPLIER> <SUPPLIER> <NAME>My Second Supplier</NAME> <INVOICES> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>11-Jan-2005</INVDATE> <INVAMT>150</INVOICEAMT> </INVOICE> … In the template sample shown in the following figure, the field called PageBreak contains the split-by-page-break syntax: Place the PageBreak field with the <?split-by-page-break:?> syntax immediately before the <?end for-each?> field. The PageBreak field sits inside the end of the SUPPLIER loop. This will ensure a page break is inserted before the occurrence of each new supplier. This method avoids the ejection of an extra page at the end of the group when using the native Microsoft Word page break after the group. Initial Page NumberSome reports require that the initial page number be set at a specified number. For example, monthly reports may be required to continue numbering from month to month. BI Publisher allows you to set the page number in the template to support this requirement. Use the following syntax in your template to set the initial page number: <?initial-page-number:pagenumber?> where pagenumber is the XML element or parameter that holds the numeric value. Example 1 - Set page number from XML data element If your XML data contains an element to carry the initial page number, for example: <REPORT> <PAGESTART>200<\PAGESTART> .... </REPORT> Enter the following in your template: <?initial-page-number:PAGESTART?> Your initial page number will be the value of the PAGESTART element, which in this case is 200. Example 2 - Set page number by passing a parameter value If you define a parameter called PAGESTART, you can pass the initial value by calling the parameter. Enter the following in your template: <?initial-page-number:$PAGESTART?> Note: You must first declare the parameter in your template. See Defining Parameters in Your Template. Last Page Only ContentBI Publisher supports the Microsoft Word functionality to specify a different page layout for the first page, odd pages, and even pages. To implement these options, simply select Page Setup from the File menu, then select the Layout tab. BI Publisher will recognize the settings you make in this dialog. However, Microsoft Word does not provide settings for a different last page only. This is useful for documents such as checks, invoices, or purchase orders on which you may want the content such as the check or the summary in a specific place only on the last page. BI Publisher provides this ability. To utilize this feature, you must:
Any content on the page that occurs above or below these two tags will appear only on the last page of the report. Also, note that because this command explicitly specifies the content of the final page, any desired headers or footers previously defined for the report must be reinserted on the last page. This example uses the last page only feature for a report that generates an invoice listing with a summary to appear at the bottom of the last page. Assume the following XML: <?xml version="1.0" encoding="WINDOWS-1252"?> <INVOICELIST> <VENDOR> <VENDOR_NAME>Nuts and Bolts Limited</VENDOR_NAME> <ADDRESS>1 El Camino Real, Redwood City, CA 94065</ADDRESS> <INVOICE> <INV_TYPE>Standard</INV_TYPE> <INVOICE_NUM>981110</INVOICE_NUM> <INVOICE_DATE>10-NOV-04</INVOICE_DATE> <INVOICE_CURRENCY_CODE>EUR</INVOICE_CURRENCY_CODE> <ENT_AMT>122</ENT_AMT> <ACCTD_AMT>122</ACCTD_AMT> <VAT_CODE>VAT22%</VAT_CODE> </INVOICE> <INVOICE> <INV_TYPE>Standard</INV_TYPE> <INVOICE_NUM>100000</INVOICE_NUM> <INVOICE_DATE>28-MAY-04</INVOICE_DATE> <INVOICE_CURRENCY_CODE>FIM</INVOICE_CURRENCY_CODE> <ENT_AMT>122</ENT_AMT> <ACCTD_AMT>20.33</ACCTD_AMT> <VAT_CODE>VAT22%</VAT_CODE> </INVOICE> </VENDOR> <VENDOR> ... <INVOICE> ... </INVOICE> </VENDOR> <SUMMARY> <SUM_ENT_AMT>61435</SUM_ENT_AMT> <SUM_ACCTD_AMT>58264.68</SUM_ACCTD_AMT> <TAX_CODE>EU22%</TAX_CODE> </SUMMARY> </INVOICELIST> The report should show each VENDOR and their INVOICE data with a SUMMARY section that appears only on the last page, placed at the bottom of the page. The template for this is shown in the following figure: Template Page One Insert a Microsoft Word section break (type: next page) on the first page of the template. For the final page, insert new line characters to position the summary table at the bottom of the page. The summary table is shown in the following figure: Last Page Only Layout In this example:
If your reports contains headers and footers that you want to carry over onto the last page, you must reinsert them on the last page. For more information about headers and footers see Defining Headers and Footers. You must insert a section break (type: next page) into the document to specify the last page layout. This example is available in the samples folder of the Oracle BI Publisher Template Builder for Word installation. It is important to note that if the report is only one page in length, the first page layout will be used. If your report requires that a single page report should default to the last page layout (such as in a check printing implementation) then you can use the following alternate syntax for the "Last Page Placeholder" on the last page: <?start@last-page-first:body?> <?end body?> Substituting this syntax will result in the last page layout for reports that are only one page long. End on Even or End on Odd PageIf your report has different odd and even page layouts, you may want to force your report to end specifically on an odd or even page. For example, you may include the terms and conditions of a purchase order in the footer of your report using the different odd/even footer functionality (see Different First Page and Different Odd and Even Page Support) and you want to ensure that the terms and conditions are printed on the final page. Or, you may have binding requirements to have your report end on an even page, without specific layout. To end on an even page with layout: Insert the following syntax in a form field in your template: <?section:force-page-count;'end-on-even-layout'?> To end on an odd page layout: <?section:force-page-count;'end-on-odd-layout'?> If you do not have layout requirements for the final page, but would like a blank page ejected to force the page count to the preferred odd or even, use the following syntax: <?section:force-page-count;'end-on-even'?> or <?section:force-page-count;'end-on-odd'?> HyperlinksBI Publisher supports several different types of hyperlinks. The hyperlinks can be fixed or dynamic and can link to either internal or external destinations. Hyperlinks can also be added to shapes.
Inserting Internal LinksInsert internal links into your template using Microsoft Word's Bookmark feature.
At runtime, the link will be maintained in your generated report. Table of ContentsBI Publisher supports the table of contents generation feature of the RTF specification. Follow your word processing application's procedures for inserting a table of contents. BI Publisher also provides the ability to create dynamic section headings in your document from the XML data. You can then incorporate these into a table of contents. To create dynamic headings:
At runtime the TOC placeholders and heading text will be substituted. Generating Bookmarks in PDF OutputIf you have defined a table of contents in your RTF template, you can use your table of contents definition to generate links in the Bookmarks tab in the navigation pane of your output PDF. The bookmarks can be either static or dynamically generated. For information on creating the table of contents, see Table of Contents.
Check BoxesYou can include a check box in your template that you can define to display as checked or unchecked based on a value from the incoming data. To define a check box in your template:
Drop Down ListsBI Publisher allows you to use the drop-down form field to create a cross-reference in your template from your XML data to some other value that you define in the drop-down form field. For example, suppose you have the following XML: <countries> <country> <name>Chad</name> <population>7360000</population> <continentIndex>5</continentIndex> </country> <country> <name>China</name> <population>1265530000</population> <continentIndex>1</continentIndex> </country> <country> <name>Chile</name> <population>14677000</population> <continentIndex>3</continentIndex> </country> . . . </countries> Notice that each <country> entry has a <continentindex> entry, which is a numeric value to represent the continent. Using the drop-down form field, you can create an index in your template that will cross-reference the <continentindex> value to the actual continent name. You can then display the name in your published report. To create the index for the continent example:
Using the check box and drop-down list features, you can create a report to display population data with check boxes to demonstrate figures that reach a certain limit. An example is shown in the following figure: The template to create this report is shown in the next figure: where the fields have the following values:
Conditional FormattingConditional formatting occurs when a formatting element appears only when a certain condition is met. BI Publisher supports the usage of simple "if" statements, as well as more complex "choose" expressions. The conditional formatting that you specify can be XSL or XSL:FO code, or you can specify actual RTF objects such as a table or data. For example, you can specify that if reported numbers reach a certain threshold, they will display shaded in red. Or, you can use this feature to hide table columns or rows depending on the incoming XML data. If StatementsUse an if statement to define a simple condition; for example, if a data field is a specific value.
For example, to set up the Payables Invoice Register to display invoices only when the Supplier name is "Company A", insert the syntax <?if:VENDOR_NAME='COMPANY A'?> before the Supplier field on the template. Enter the <?end if?> tag after the invoices table. This example is displayed in the figure below. Note that you can insert the syntax in form fields, or directly into the template. If Statements in Boilerplate TextAssume you want to incorporate an "if" statement into the following free-form text: The program was (not) successful. You only want the "not" to display if the value of an XML tag called <SUCCESS> equals "N". To achieve this requirement, you must use the BI Publisher context command to place the if statement into the inline sequence rather than into the block (the default placement). Note: For more information on context commands, see Using Context Commands. For example, if you construct the code as follows: The program was <?if:SUCCESS='N'?>not<?end if?> successful. The following undesirable result will occur: The program was not successful. because BI Publisher applies the instructions to the block by default. To specify that the if statement should be inserted into the inline sequence, enter the following: The program was <?if@inlines:SUCCESS='N'?>not<?end if?> successful. This construction will result in the following display: The program was successful. If SUCCESS does not equal 'N'; or The program was not successful. If SUCCESS equals 'N'. If-then-Else StatementsBI Publisher supports the common programming construct "if-then-else". This is extremely useful when you need to test a condition and conditionally show a result. For example: IF X=0 THEN Y=2 ELSE Y=3 END IF You can also nest these statements as follows: IF X=0 THEN Y=2 ELSE IF X=1 THEN Y=10 ELSE Y=100 END IF Use the following syntax to construct an if-then-else statement in your RTF template: <?xdofx:if element_condition then result1 else result2 end if?> For example, the following statement tests the AMOUNT element value. If the value is greater than 1000, show the word "Higher"; if it is less than 1000, show the word "Lower"; if it is equal to 1000, show "Equal": <?xdofx:if AMOUNT > 1000 then 'Higher' else if AMOUNT < 1000 then 'Lower' else 'Equal' end if?> Choose StatementsUse the choose, when, and otherwise elements to express multiple conditional tests. If certain conditions are met in the incoming XML data then specific sections of the template will be rendered. This is a very powerful feature of the RTF template. In regular XSL programming, if a condition is met in the choose command then further XSL code is executed. In the template, however, you can actually use visual widgets in the conditional flow (in the following example, a table). Use the following syntax for these elements: <?choose:?> <?when:expression?> <?otherwise?> "Choose" Conditional Formatting ExampleThis example shows a choose expression in which the display of a row of data depends on the value of the fields EXEMPT_FLAG and POSTED_FLAG. When the EXEMPT_FLAG equals "^", the row of data will render light gray. When POSTED_FLAG equals "*" the row of data will render shaded dark gray. Otherwise, the row of data will render with no shading. In the following figure, the form field default text is displayed. The form field help text entries are shown in the table following the example.
Column FormattingYou can conditionally show and hide columns of data in your document output. The following example demonstrates how to set up a table so that a column is only displayed based on the value of an element attribute. This example will show a report of a price list, represented by the following XML: <items type="PUBLIC"> <! - can be marked ‘PRIVATE' - > <item> <name>Plasma TV</name> <quantity>10</quantity> <price>4000</price> </item> <item> <name>DVD Player</name> <quantity>3</quantity> <price>300</price> </item> <item> <name>VCR</name> <quantity>20</quantity> <price>200</price> </item> <item> <name>Receiver</name> <quantity>22</quantity> <price>350</price> </item> </items> Notice the type attribute associated with the items element. In this XML it is marked as "PUBLIC" meaning the list is a public list rather than a "PRIVATE" list. For the "public" version of the list we do not want to show the quantity column in the output, but we want to develop only one template for both versions based on the list type. The following figure is a simple template that will conditionally show or hide the quantity column: The following table shows the entries made in the template for the example:
The conditional column syntax is the "if" statement syntax with the addition of the @column clause. It is the @column clause that instructs BI Publisher to hide or show the column based on the outcome of the if statement. If you did not include the @column the data would not display in your report as a result of the if statement, but the column still would because you had drawn it in your template. Note: The @column clause is an example of a context command. For more information, see Using Context Commands. The example will render the output shown in the following figure: If the same XML data contained the type attribute set to "PRIVATE" the following output would be rendered from the same template: Row FormattingBI Publisher allows you to specify formatting conditions as the row-level of a table. Examples of row-level formatting are:
Conditionally Displaying a Row To display only rows that meet a certain condition, insert the <?if:condition?> <?end if?> tags at the beginning and end of the row, within the for-each tags for the group. This is demonstrated in the following sample template. Note the following fields from the sample figure:
Conditionally Highlighting a Row This example demonstrates how to set a background color on every other row. The template to create this effect is shown in the following figure: The following table shows values of the form fields in the template:
In the preceding example, note the "format;" field. It contains an if statement with a "row" context (@row). This sets the context of the if statement to apply to the current row. If the condition is true, then the <xsl:attribute> for the background color of the row will be set to light gray. This will result in the following output: Note: For more information about context commands, see Using Context Commands. Cell HighlightingThe following example demonstrates how to conditionally highlight a cell based on a value in the XML file. For this example we will use the following XML: <accounts> <account> <number>1-100-3333</number> <debit>100</debit> <credit>300</credit> </account> <account> <number>1-101-3533</number> <debit>220</debit> <credit>30</credit> </account> <account> <number>1-130-3343</number> <debit>240</debit> <credit>1100</credit> </account> <account> <number>1-153-3033</number> <debit>3000</debit> <credit>300</credit> </account> </accounts> The template lists the accounts and their credit and debit values. In the final report we want to highlight in red any cell whose value is greater than 1000. The template for this is shown in the following figure: The field definitions for the template are shown in the following table:
The code to highlight the debit column as shown in the table is: <?if:debit>1000?> <xsl:attribute xdofo:ctx="block" name="background-color">red </xsl:attribute> <?end if?> The "if" statement is testing if the debit value is greater than 1000. If it is, then the next lines are invoked. Notice that the example embeds native XSL code inside the "if" statement. The "attribute" element allows you to modify properties in the XSL. The xdofo:ctx component is an BI Publisher feature that allows you to adjust XSL attributes at any level in the template. In this case, the background color attribute is changed to red. To change the color attribute, you can use either the standard HTML names (for example, red, white, green) or you can use the hexadecimal color definition (for example, #FFFFF). The output from this template is displayed in the following figure: Page-Level CalculationsDisplaying Page TotalsBI Publisher allows you to display calculated page totals in your report. Because the page is not created until publishing time, the totaling function must be executed by the formatting engine. Note: Page totaling is performed in the PDF-formatting layer. Therefore this feature is not available for other outputs types: HTML, RTF, Excel. Note: Note that this page totaling function will only work if your source XML has raw numeric values. The numbers must not be preformatted. Because the page total field does not exist in the XML input data, you must define a variable to hold the value. When you define the variable, you associate it with the element from the XML file that is to be totaled for the page. Once you define total fields, you can also perform additional functions on the data in those fields. To declare the variable that is to hold your page total, insert the following syntax immediately following the placeholder for the element that is to be totaled: <?add-page-total:TotalFieldName;'element'?> where TotalFieldName is the name you assign to your total (to reference later) and 'element' is the XML element field to be totaled. You can add this syntax to as many fields as you want to total. Then when you want to display the total field, enter the following syntax: <?show-page-total:TotalFieldName;'Oracle-number-format'?> where TotalFieldName is the name you assigned to give the page total field above and Oracle-number-format is the format you wish to use to for the display, using the Oracle format mask (for example: C9G999D00). For the list of Oracle format mask symbols, see Using the Oracle Format Mask. The following example shows how to set up page total fields in a template to display total credits and debits that have displayed on the page, and then calculate the net of the two fields. This example uses the following XML: <balance_sheet> <transaction> <debit>100</debit> <credit>90</credit> </transaction> <transaction> <debit>110</debit> <credit>80</credit> </transaction> … <\balance_sheet> The following figure shows the table to insert in the template to hold the values: The following table shows the form field entries made in the template for the example table:
Note that on the field defined as "net" we are actually carrying out a calculation on the values of the credit and debit elements. Now that you have declared the page total fields, you can insert a field in your template where you want the page totals to appear. Reference the calculated fields using the names you supplied (in the example, ct and dt). The syntax to display the page totals is as follows: For example, to display the debit page total, enter the following: <?show-page-total:dt;'C9G990D00';'(C9G990D00)'?> Therefore to complete the example, place the following at the bottom of the template page, or in the footer: Page Total Debit: <?show-page-total:dt;'C9G990D00';'(C9G990D00)'?> Page Total Credit: <?show-page-total:ct;'C9G990D00';'(C9G990D00)'?> Page Total Balance: <?show-page-total:net;'C9G990D00';'(C9G990D00)'?> The output for this report is shown in the following graphic: Brought Forward/Carried Forward TotalsMany reports require that a page total be maintained throughout the report output and be displayed at the beginning and end of each page. These totals are known as "brought forward/carried forward" totals. Note: The totaling for the brought forward and carried forward fields is performed in the PDF-formatting layer. Therefore this feature is not available for other outputs types: HTML, RTF, Excel. An example is displayed in the following figure: At the end of the first page, the page total for the Amount element is displayed as the Carried Forward total. At the top of the second page, this value is displayed as the Brought Forward total from the previous page. At the bottom of the second page, the brought forward value plus the total for that page is calculated and displayed as the new Carried Forward value, and this continues throughout the report. This functionality is an extension of the Page Totals feature. The following example walks through the syntax and setup required to display the brought forward and carried forward totals in your published report. Assume you have the following XML: <?xml version="1.0" encoding="WINDOWS-1252"?> <INVOICES> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>1-Jan-2005</INVDATE> <INVAMT>100</INVOICEAMT> </INVOICE> <INVOICE> <INVNUM>10001-2</INVNUM> <INVDATE>10-Jan-2005</INVDATE> <INVAMT>200</INVOICEAMT> </INVOICE> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>11-Jan-2005</INVDATE> <INVAMT>150</INVOICEAMT> </INVOICE> . . . </INVOICES> The following sample template creates the invoice table and declares a placeholder that will hold your page total: The fields in the template have the following values:
To display the brought forward total at the top of each page (except the first), use the following syntax: <xdofo:inline-total display-condition="exceptfirst" name="InvAmt"> Brought Forward: <xdofo:show-brought-forward name="InvAmt" format="99G999G999D00"/> </xdofo:inline-total> The following table describes the elements comprising the brought forward syntax:
Insert the brought forward object at the top of the template where you want the brought forward total to display. If you place it in the body of the template, you can insert the syntax in a form field. If you want the brought forward total to display in the header, you must insert the full code string into the header because Microsoft Word does not support form fields in the header or footer regions. However, you can alternatively use the start body/end body syntax which allows you to define what the body area of the report will be. BI Publisher will recognize any content above the defined body area as header content, and any content below as the footer. This allows you to use form fields. See Multiple or Complex Headers and Footers for details. Place the carried forward object at the bottom of your template where you want the total to display. The carried forward object for our example is as follows: <xdofo:inline-total display-condition="exceptlast" name="InvAmt"> Carried Forward: <xdofo:show-carry-forward name="InvAmt" format="99G999G999D00"/> </xdofo:inline-total> Note the following differences with the brought-forward object:
You are not limited to a single value in your template, you can create multiple brought forward/carried forward objects in your template pointing to various numeric elements in your data. Running TotalsThe variable functionality (see Using Variables) can be used to add a running total to your invoice listing report. This example assumes the following XML structure: <?xml version="1.0" encoding="WINDOWS-1252"?> <INVOICES> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>1-Jan-2005</INVDATE> <INVAMT>100</INVOICEAMT> </INVOICE> <INVOICE> <INVNUM>10001-2</INVNUM> <INVDATE>10-Jan-2005</INVDATE> <INVAMT>200</INVOICEAMT> </INVOICE> <INVOICE> <INVNUM>10001-1</INVNUM> <INVDATE>11-Jan-2005</INVDATE> <INVAMT>150</INVOICEAMT> </INVOICE> </INVOICES> Using this XML, we want to create the report that contains running totals as shown in the following figure: To create the Running Total field, define a variable to track the total and initialize it to 0. The template is shown in the following figure: The values for the form fields in the template are shown in the following table:
Data HandlingSortingYou can sort a group by any element within the group. Insert the following syntax within the group tags: <?sort:element name?> For example, to sort the Payables Invoice Register (shown at the beginning of this chapter) by Supplier (VENDOR_NAME), enter the following after the <?for-each:G_VENDOR_NAME?> tag: <?sort:VENDOR_NAME?> To sort a group by multiple fields, just insert the sort syntax after the primary sort field. To sort by Supplier and then by Invoice Number, enter the following <?sort:VENDOR_NAME?> <?sort:INVOICE_NUM?> Checking for NullsWithin your XML data there are three possible scenarios for the value of an element:
In your report layout, you may want to specify a different behavior depending on the presence of the element and its value. The following examples show how to check for each of these conditions using an "if" statement. The syntax can also be used in other conditional formatting constructs.
Regrouping the XML DataThe RTF template supports the XSL 2.0 for-each-group standard that allows you to regroup XML data into hierarchies that are not present in the original data. With this feature, your template does not have to follow the hierarchy of the source XML file. You are therefore no longer limited by the structure of your data source. XML SampleTo demonstrate the for-each-group standard, the following XML data sample of a CD catalog listing will be regrouped in a template: <CATALOG> <CD> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <COMPANY>Columbia</COMPANY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD> <TITLE>Hide Your Heart</TITLE> <ARTIST>Bonnie Tylor</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>CBS Records</COMPANY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> <CD> <TITLE>Still got the blues</TITLE> <ARTIST>Gary More</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin Records</COMPANY> <PRICE>10.20</PRICE> <YEAR>1990</YEAR> </CD> <CD> <TITLE>This is US</TITLE> <ARTIST>Gary Lee</ARTIST> <COUNTRY>UK</COUNTRY> <COMPANY>Virgin Records</COMPANY> <PRICE>12.20</PRICE> <YEAR>1990</YEAR> </CD> Using the regrouping syntax, you can create a report of this data that groups the CDs by country and then by year. You are not limited by the data structure presented. Regrouping SyntaxTo regroup the data, use the following syntax: <?for-each-group: BASE-GROUP;GROUPING-ELEMENT?> For example, to regroup the CD listing by COUNTRY, enter the following in your template: <?for-each-group:CD;COUNTRY?> The elements that were at the same hierarchy level as COUNTRY are now children of COUNTRY. You can then refer to the elements of the group to display the values desired. To establish nested groupings within the already defined group, use the following syntax: <?for-each:current-group(); GROUPING-ELEMENT?> For example, after declaring the CD grouping by COUNTRY, you can then further group by YEAR within COUNTRY as follows: <?for-each:current-group();YEAR?> At runtime, BI Publisher will loop through the occurrences of the new groupings, displaying the fields that you defined in your template. Note: This syntax is a simplification of the XSL for-each-group syntax. If you choose not to use the simplified syntax above, you can use the XSL syntax as shown below. The XSL syntax can only be used within a form field of the template. <xsl:for-each-group select=expression group-by="string expression" group-adjacent="string expression" group-starting-with=pattern> <!--Content: (xsl:sort*, content-constructor) --> </xsl:for-each-group> Template ExampleThe following figure shows a template that displays the CDs by Country, then Year, and lists the details for each CD: The following table shows the BI Publisher syntax entries made in the form fields of the preceding template:
This template produces the following output when merged with the XML file: Regrouping by an ExpressionRegrouping by an expression allows you to apply a function or command to a data element, and then group the data by the returned result. To use this feature, state the expression within the regrouping syntax as follows: <?for-each:BASE-GROUP; GROUPING-EXPRESSION?> To demonstrate this feature, an XML data sample that simply contains average temperatures per month will be used as input to a template that calculates the number of months having an average temperature within a certain range. The following XML sample is composed of <temp> groups. Each <temp> group contains a <month> element and a <degree> element, which contains the average temperature for that month: <temps> <temp> <month>Jan</month> <degree>11</degree> </temp> <temp> <month>Feb</month> <degree>14</degree> </temp> <temp> <month>Mar</month> <degree>16</degree> </temp> <temp> <month>Apr</month> <degree>20</degree> </temp> <temp> <month>May</month> <degree>31</degree> </temp> <temp> <month>Jun</month> <degree>34</degree> </temp> <temp> <month>Jul</month> <degree>39</degree> </temp> <temp> <month>Aug</month> <degree>38</degree> </temp> <temp> <month>Sep</month> <degree>24</degree> </temp> <temp> <month>Oct</month> <degree>28</degree> </temp> <temp> <month>Nov</month> <degree>18</degree> </temp> <temp> <month>Dec</month> <degree>8</degree> </temp> </temps> You want to display this data in a format showing temperature ranges and a count of the months that have an average temperature to satisfy those ranges, as follows: Using the for-each-group command you can apply an expression to the <degree> element that will enable you to group the temperatures by increments of 10 degrees. You can then display a count of the members of each grouping, which will be the number of months having an average temperature that falls within each range. The template to create the above report is shown in the following figure: The following table shows the form field entries made in the template:
Note the following about the form field tags:
Using VariablesUpdateable variables differ from standard XSL variables <xsl:variable> in that they are updateable during the template application to the XML data. This allows you to create many new features in your templates that require updateable variables. The variables use a "set and get" approach for assigning, updating, and retrieving values. Use the following syntax to declare/set a variable value: <?xdoxslt:set_variable($_XDOCTX, 'variable name', value)?> Use the following syntax to retrieve a variable value: <?xdoxslt:get_variable($_XDOCTX, 'variable name')?> You can use this method to perform calculations. For example: <?xdoxslt:set_variable($_XDOCTX, 'x', xdoxslt:get_variable($_XDOCTX, 'x' + 1)?> This sets the value of variable 'x' to its original value plus 1, much like using "x = x + 1". The $_XDOCTX specifies the global document context for the variables. In a multi-threaded environment there may be many transformations occurring at the same time, therefore the variable must be assigned to a single transformation. See the section on Running Totals for an example of the usage of updateable variables. Defining ParametersYou can pass runtime parameter values into your template. These can then be referenced throughout the template to support many functions. For example, you can filter data in the template, use a value in a conditional formatting block, or pass property values (such as security settings) into the final document. Note: For BI Publisher Enterprise users, all name-value parameter pairs are passed to the template. You must register the parameters that you wish to utilize in your template using the syntax described below. Using a parameter in a template
Example: Passing an invoice threshold parameter This example illustrates how to declare a parameter in your template that will filter your data based on the value of the parameter. The following XML sample lists invoice data: <INVOICES> <INVOICE> <INVOICE_NUM>981110</INVOICE_NUM> <AMOUNT>1100</AMOUNT> </INVOICE> <INVOICE> <INVOICE_NUM>981111</INVOICE_NUM> <AMOUNT>250</AMOUNT> </INVOICE> <INVOICE> <INVOICE_NUM>981112</INVOICE_NUM> <AMOUNT>8343</AMOUNT> </INVOICE> . . . </INVOICES> The following figure displays a template that accepts a parameter value to limit the invoices displayed in the final document based on the parameter value.
In this template, only INVOICE elements with an AMOUNT greater than the InvThresh parameter value will be displayed. If we pass in a parameter value of 1,000, the following output shown in the following figure will result: Notice the second invoice does not display because its amount was less than the parameter value. Setting PropertiesBI Publisher properties that are available in the BI Publisher Configuration file can alternatively be embedded into the RTF template. The properties set in the template are resolved at runtime by the BI Publisher engine. You can either hard code the values in the template or embed the values in the incoming XML data. Embedding the properties in the template avoids the use of the configuration file. Note: See BI Publisher Configuration File for more information about the BI Publisher Configuration file and the available properties. For example, if you use a nonstandard font in your template, rather than specify the font location in the configuration file, you can embed the font property inside the template. If you need to secure the generated PDF output, you can use the BI Publisher PDF security properties and obtain the password value from the incoming XML data. To add an BI Publisher property to a template, use the Microsoft Word Properties dialog (available from the File menu), and enter the following information: Name - enter the BI Publisher property name prefixed with "xdo-" Type - select "Text" Value - enter the property value. To reference an element from the incoming XML data, enter the path to the XML element enclosed by curly braces. For example: {/root/password} The following figure shows the Properties dialog: Embedding a Font Reference For this example, suppose you want to use a font in the template called "XMLPScript". This font is not available as a regular font on your server, therefore you must tell BI Publisher where to find the font at runtime. You tell BI Publisher where to find the font by setting the "font" property. Assume the font is located in "/tmp/fonts", then you would enter the following in the Properties dialog: Name: xdo-font.XMLPScript.normal.normal Type: Text Value: truetype./tmp/fonts/XMLPScript.ttf When the template is applied to the XML data on the server, BI Publisher will look for the font in the /tmp/fonts directory. Note that if the template is deployed in multiple locations, you must ensure that the path is valid for each location. For more information about setting font properties, see Font Definitions. Securing a PDF Output For this example, suppose you want to use a password from the XML data to secure the PDF output document. The XML data is as follows: <PO> <security>true</security> <password>welcome</password> <PO_DETAILS> .. </PO> In the Properties dialog set two properties: pdf-security to set the security feature as enabled or not, and pdf-open-password to set the password. Enter the following in the Properties dialog: Name: xdo-pdf-security Type: Text Value: {/PO/security} Name: xdo-pdf-open-password Type: Text Value: {/PO/password} Storing the password in the XML data is not recommended if the XML will persist in the system for any length of time. To avoid this potential security risk, you can use a template parameter value that is generated and passed into the template at runtime. For example, you could set up the following parameters:
You would then enter the following in the Properties dialog: Name: xdo-pdf-security Type: Text Value: {$PDFSec} Name: xdo-pdf-open-password Type: Text Value: {$PDFPWD} For more information about template parameters, see Defining Parameters in Your Template. Advanced Report LayoutsBatch ReportsIt is a common requirement to print a batch of documents, such as invoices or purchase orders in a single PDF file. Because these documents are intended for different customers, each document will require that the page numbering be reset and that page totals are specific to the document. If the header and footer display fields from the data (such as customer name) these will have to be reset as well. BI Publisher supports this requirement through the use of a context command. This command allows you to define elements of your report to a specific section. When the section changes, these elements are reset. The following example demonstrates how to reset the header and footer and page numbering within an output file: The following XML sample is a report that contains multiple invoices: ... <LIST_G_INVOICE> <G_INVOICE> <BILL_CUST_NAME>Vision, Inc. </BILL_CUST_NAME> <TRX_NUMBER>2345678</TRX_NUMBER> ... </G_INVOICE> <G_INVOICE> <BILL_CUST_NAME>Oracle, Inc. </BILL_CUST_NAME> <TRX_NUMBER>2345685</TRX_NUMBER> ... </G_INVOICE> ... </LIST_G_INVOICE> ... Each G_INVOICE element contains an invoice for a potentially different customer. To instruct BI Publisher to start a new section for each occurrence of the G_INVOICE element, add the @section command to the opening for-each statement for the group, using the following syntax: <?for-each@section:group name?> where group_name is the name of the element for which you want to begin a new section. For example, the for-each grouping statement for this example will be as follows: <?for-each@section:G_INVOICE?> The closing <?end for-each?> tag is not changed. The following figure shows a sample template. Note that the G_INVOICE group for-each declaration is still within the body of the report, even though the headers will be reset by the command. The following table shows the values of the form fields from the example:
Now for each new occurrence of the G_INVOICE element, a new section will begin. The page numbers will restart, and if header or footer information is derived from the data, it will be reset as well. Cross-Tab SupportThe columns of a cross-tab report are data dependent. At design-time you do not know how many columns will be reported, or what the appropriate column headings will be. Moreover, if the columns should break onto a second page, you need to be able to define the row label columns to repeat onto subsequent pages. The following example shows how to design a simple cross-tab report that supports these features. This example uses the following XML sample: <ROWSET> <RESULTS> <INDUSTRY>Motor Vehicle Dealers</INDUSTRY> <YEAR>2005</YEAR> <QUARTER>Q1</QUARTER> <SALES>1000</SALES> </RESULTS> <RESULTS> <INDUSTRY>Motor Vehicle Dealers</INDUSTRY> <YEAR>2005</YEAR> <QUARTER>Q2</QUARTER> <SALES>2000</SALES> </RESULTS> <RESULTS> <INDUSTRY>Motor Vehicle Dealers</INDUSTRY> <YEAR>2004</YEAR> <QUARTER>Q1</QUARTER> <SALES>3000</SALES> </RESULTS> <RESULTS> <INDUSTRY>Motor Vehicle Dealers</INDUSTRY> <YEAR>2004</YEAR> <QUARTER>Q2</QUARTER> <SALES>3000</SALES> </RESULTS> <RESULTS> <INDUSTRY>Motor Vehicle Dealers</INDUSTRY> <YEAR>2003</YEAR> ... </RRESULTS> <RESULTS> <INDUSTRY>Home Furnishings</INDUSTRY> ... </RESULTS> <RESULTS> <INDUSTRY>Electronics</INDUSTRY> ... </RESULTS> <RESULTS> <INDUSTRY>Food and Beverage</INDUSTRY> ... </RESULTS> </ROWSET> From this XML we will generate a report that shows each industry and totals the sales by year as shown in the following figure: The template to generate this report is shown in the following figure. The form field entries are shown in the subsequent table. The form fields in the template have the following values:
Note that only the first row uses the @column context to determine the number of columns for the table. All remaining rows need to use the @cell context to create the table cells for the column. (For more information about context commands, see Using the Context Commands.) Dynamic Data ColumnsThe ability to construct dynamic data columns is a very powerful feature of the RTF template. Using this feature you can design a template that will correctly render a table when the number of columns required by the data is variable. For example, you are designing a template to display columns of test scores within specific ranges. However, you do not how many ranges will have data to report. You can define a dynamic data column to split into the correct number of columns at runtime. Use the following tags to accommodate the dynamic formatting required to render the data correctly:
Defining Columns to Repeat Across PagesIf your table columns expand horizontally across more than one page, you can define how many row heading columns you want to repeat on every page. Use the following syntax to specify the number of columns to repeat: <?horizontal-break-table:number?> where number is the number of columns (starting from the left) to repeat. Note that this functionality is supported for PDF output only.. Example of Dynamic Data ColumnsA template is required to display test score ranges for school exams. Logically, you want the report to be arranged as shown in the following table:
but you do not know how many Test Score Ranges will be reported. The number of Test Score Range columns is dynamic, depending on the data. The following XML data describes these test scores. The number of occurrences of the element <TestScoreRange> will determine how many columns are required. In this case there are five columns: 0-20, 21-40, 41-60, 61-80, and 81-100. For each column there is an amount element (<NumOfStudents>) and a column width attribute (<TestScore width="15">). <?xml version="1.0" encoding="utf-8"?> <TestScoreTable> <TestScores> <TestCategory>Mathematics</TestCategory> <TestScore width ="15"> <TestScoreRange>0-20</TestScoreRange> <NumofStudents>30</NumofStudents> </TestScore> <TestScore width ="20"> <TestScoreRange>21-40</TestScoreRange> <NumofStudents>45</NumofStudents> </TestScore> <TestScore width ="15"> <TestScoreRange>41-60</TestScoreRange> <NumofStudents>50</NumofStudents> </TestScore> <TestScore width ="20"> <TestScoreRange>61-80</TestScoreRange> <NumofStudents>102</NumofStudents> </TestScore> <TestScore width ="15"> <TestScoreRange>81-100</TestScoreRange> <NumofStudents>22</NumofStudents> </TestScore> </TestScores> <TestScoreTable> Using the dynamic column tags in form fields, set up the table in two columns as shown in the following figure. The first column, "Test Score" is static. The second column, "Column Header and Splitting" is the dynamic column. At runtime this column will split according to the data, and the header for each column will be appropriately populated. The Default Text entry and Form Field Help entry for each field are listed in the table following the figure. (See Form Field Method for more information on using form fields).
The template will render the output shown in the following figure: Number and FormattingNumber FormattingBI Publisher supports two methods for specifying the number format:
Note: You can also use the native XSL format-number function to format numbers. See: Native XSL Number Formatting. Use only one of these methods. If the number format mask is specified using both methods, the data will be formatted twice, causing unexpected behavior. The group separator and the number separator will be set at runtime based on the template locale. This is applicable for both the Oracle format mask and the MS format mask. Data Source RequirementsTo use the Oracle format mask or the Microsoft format mask, the numbers in your data source must be in a raw format, with no formatting applied (for example: 1000.00). If the number has been formatted for European countries (for example: 1.000,00) the format will not work. Note: The BI Publisher parser requires the Java BigDecimal string representation. This consists of an optional sign ("-") followed by a sequence of zero or more decimal digits (the integer), optionally followed by a fraction, and optionally followed by an exponent. For example: -123456.3455e-3. Translation ConsiderationsIf you are designing a template to be translatable, using currency in the Microsoft format mask is not recommended unless you want the data reported in the same currency for all translations. Using the MS format mask sets the currency in the template so that it cannot be updated at runtime. Instead, use the Oracle format mask. For example, L999G999G999D99, where "L" will be replaced by the currency symbol based on the locale at runtime. Do not include "%" in the format mask because this will fix the location of the percent sign in the number display, while the desired position could be at the beginning or the end of a number, depending on the locale. Using the Microsoft Number Format MaskTo format numeric values, use Microsoft Word's field formatting features available from the Text Form Field Options dialog box. The following graphic displays an example: To apply a number format to a form field:
Supported Microsoft Format Mask DefinitionsThe following table lists the supported Microsoft format mask definitions:
Note: Subpattern boundary: A pattern contains a positive and negative subpattern, for example, "#,##0.00;(#,##0.00)". Each subpattern has a prefix, numeric part, and suffix. The negative subpattern is optional. If absent, the positive subpattern prefixed with the localized minus sign ("-" in most locales) is used as the negative subpattern. That is, "0.00" alone is equivalent to "0.00;-0.00". If there is an explicit negative subpattern, it serves only to specify the negative prefix and suffix. The number of digits, minimal digits, and other characteristics are all the same as the positive pattern. That means that "#,##0.0#;(#)" produces precisely the same behavior as "#,##0.0#;(#,##0.0#)". Using the Oracle Format MaskTo apply the Oracle format mask to a form field:
where fieldname is the XML tag name of the data element you are formatting and 999G999D99 is the mask definition. The following graphic shows an example Form Field Help Text dialog entry for the data element "empno": The following table lists the supported Oracle number format mask symbols and their definitions:
Date FormattingBI Publisher supports three methods for specifying the date format:
Only one method should be used. If both the Oracle and MS format masks are specified, the data will be formatted twice causing unexpected behavior. Data Source RequirementsTo use the Microsoft format mask or the Oracle format mask, the date from the XML data source must be in canonical format. This format is: YYYY-MM-DDThh:mm:ss+HH:MM where
An example of this construction is: 2005-01-01T09:30:10-07:00 The data after the "T" is optional, therefore the following date: 2005-01-01 can be formatted using either date formatting option. Note that if you do not include the time zone offset, the time will be formatted to the UTC time. Translation Considerationsdate_format Using the Microsoft Date Format MaskTo apply a date format to a form field:
If you do not specify the mask in the Date format field, the abstract format mask "MEDIUM" will be used as default. See Oracle Abstract Format Masks for the description. The following figure shows the Text Form Field Options dialog box with a date format applied: The following table lists the supported Microsoft date format mask components:
Using the Oracle Format MaskTo apply the Oracle format mask to a date field:
The following table lists the supported Oracle format mask components:
Default Format MaskIf you do not want to specify a format mask with either the MS method or the Oracle method, you can omit the mask definition and use the default format mask. The default format mask is the MEDIUM abstract format mask from Oracle. (See Oracle Abstract Format Masks for the definition.) To use the default option using the Microsoft method, set the Type to Date, but leave the Date format field blank in the Text Form Field Options dialog. To use the default option using the Oracle method, do not supply a mask definition to the "format-date" function call, for example: <?format-date:hiredate?> Oracle Abstract Format MasksThe abstract date format masks reflect the default implementations of date/time formatting in the I18N library. When you use one of these masks, the output generated will depend on the locale associated with the report. Specify the abstract mask using the following syntax: <?format-date:fieldname;'MASK'?> where fieldname is the XML element tag and MASK is the Oracle abstract format mask name For example: <?format-date:hiredate;'SHORT'?> <?format-date:hiredate;'LONG_TIME_TZ'?> The following table lists the abstract format masks and the sample output that would be generated for US locale:
Calendar and Timezone SupportCalendar SpecificationThe term "calendar" refers to the calendar date displayed in the published report. The following types are supported:
Use one of the following methods to set the calendar type:
Note: The calendar type specified in the template will override the calendar type set in the profile option. Time Zone SpecificationThere are two ways to specify time zone information:
If no time zone is specified, UTC is used. In the template, the time zone must be specified as a Java time zone string, for example, America/Los Angeles. The following example shows the syntax to enter in the help text field of your template: <?format-date:hiredate;'LONG_TIME_TZ';'Asia/Shanghai'?> Using External FontsBI Publisher enables you to use fonts in your output that are not normally available on the server. To set up a new font for your report output, use the font to design your template on your client machine, then make it available on the server, and configure BI Publisher to access the font at runtime.
Now you can run your report and BI Publisher will use the font in the output as designed. For PDF output, the advanced font handling features of BI Publisher embed the external font glyphs directly into the final document. The embedded font only contains the glyphs required for the document and not the complete font definition. Therefore the document is completely self-contained, eliminating the need to have external fonts installed on the printer. Advanced Barcode FormattingBI Publisher offers the ability to execute preprocessing on your data prior to applying a barcode font to the data in the output document. For example, you may need to calculate checksum values or start and end bits for the data before formatting them. The solution requires that you register a barcode encoding class with BI Publisher that can then be instantiated at runtime to carry out the formatting in the template. This is covered in Advanced Barcode Font Formatting Class Implementation. To enable the formatting feature in your template, you must use two commands in your template. The first command registers the barcode encoding class with BI Publisher. This must be declared somewhere in the template prior to the encoding command. The second is the encoding command to identify the data to be formatted. Register the Barcode Encoding ClassUse the following syntax in a form field in your template to register the barcode encoding class: <?register-barcode-vendor:java_class_name;barcode_vendor_id?> This command requires a Java class name (this will carry out the encoding) and a barcode vendor ID as defined by the class. This command must be placed in the template before the commands to encode the data in the template. For example: <?register-barcode-vendor:'oracle.apps.xdo.template.rtf.util.barcoder.BarcodeUtil';'XMLPBarVendor'?> where oracle.apps.xdo.template.rtf.util.barcoder.BarcodeUtil is the Java class and XMLPBarVendor is the vendor ID that is defined by the class. Encode the DataTo format the data, use the following syntax in a form field in your template: <?format-barcode:data;'barcode_type';'barcode_vendor_id'?> where data is the element from your XML data source to be encoded. For example: LABEL_ID barcode_type is the method in the encoding Java class used to format the data (for example: Code128a). barcode_vendor_id is the ID defined in the register-barcode-vendor field of the first command you used to register the encoding class. For example: <?format-barcode:LABEL_ID;'Code128a';'XMLPBarVendor'?> At runtime, the barcode_type method is called to format the data value and the barcode font will then be applied to the data in the final output. Advanced Design OptionsXPath is an industry standard developed by the World Wide Web Consortium (W3C). It is the method used to navigate through an XML document. XPath is a set of syntax rules for addressing the individual pieces of an XML document. You may not know it, but you have already used XPath; RTF templates use XPath to navigate through the XML data at runtime. This section contains a brief introduction to XPath principles. For more information, see the W3C Web site: http://www.w3.org/TR/xpath XPath follows the Document Object Model (DOM), which interprets an XML document as a tree of nodes. A node can be one of seven types:
Many of these elements are shown in the following sample XML, which contains a catalog of CDs: <?xml version="1.0" encoding="UTF-8"?> <! - My CD Listing - > <CATALOG> <CD cattype=Folk> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> <CD cattype=Rock> <TITLE>Hide Your Heart</TITLE> <ARTIST>Bonnie Tylor</ARTIST> <COUNTRY>UK</COUNTRY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> </CATALOG> The root node in this example is CATALOG. CD is an element, and it has an attribute cattype. The sample contains the comment My CD Listing. Text is contained within the XML document elements. Locating DataLocate information in an XML document using location-path expressions. A node is the most common search element you will encounter. Nodes in the example CATALOG XML include CD, TITLE, and ARTIST. Use a path expression to locate nodes within an XML document. For example, the following path returns all CD elements: //CATALOG/CD where the double slash (//) indicates that all elements in the XML document that match the search criteria are to be returned, regardless of the level within the document. the slash (/) separates the child nodes. All elements matching the pattern will be returned. To retrieve the individual TITLE elements, use the following command: /CATALOG/CD/TITLE This example will return the following XML: <CATALOG> <CD cattype=Folk> <TITLE>Empire Burlesque</TITLE> </CD> <CD cattype=Rock> <TITLE>Hide Your Heart</TITLE> </CD> </CATALOG> Further limit your search by using square brackets. The brackets locate elements with certain child nodes or specified values. For example, the following expression locates all CDs recorded by Bob Dylan: /CATALOG/CD[ARTIST="Bob Dylan"] Or, if each CD element did not have an PRICE element, you could use the following expression to return only those CD elements that include a PRICE element: /CATALOG/CD[PRICE] Use the bracket notation to leverage the attribute value in your search. Use the @ symbol to indicate an attribute. For example, the following expression locates all Rock CDs (all CDs with the cattype attribute value Rock): //CD[@cattype="Rock"] This returns the following data from the sample XML document: <CD cattype=Rock> <TITLE>Hide Your Heart</TITLE> <ARTIST>Bonnie Tylor</ARTIST> <COUNTRY>UK</COUNTRY> <PRICE>9.90</PRICE> <YEAR>1988</YEAR> </CD> You can also use brackets to specify the item number to retrieve. For example, the first CD element is read from the XML document using the following XPath expression: /CATALOG/CD[1] The sample returns the first CD element: <CD cattype=Folk> <TITLE>Empire Burlesque</TITLE> <ARTIST>Bob Dylan</ARTIST> <COUNTRY>USA</COUNTRY> <PRICE>10.90</PRICE> <YEAR>1985</YEAR> </CD> XPath also supports wildcards to retrieve every element contained within the specified node. For example, to retrieve all the CDs from the sample XML, use the following expression: /CATALOG/* You can combine statements with Boolean operators for more complex searches. The following expression retrieves all Folk and Rock CDs, thus all the elements from the sample: //CD[@cattype="Folk"]|//CD[@cattype="Rock"] The pipe (|) is equal to the logical OR operator. In addition, XPath recognizes the logical OR and AND, as well as the equality operators: <=, <, >, >=, ==, and !=. For example, we can find all CDs released in 1985 or later using the following expression: /CATALOG/CD[YEAR >=1985] Starting ReferenceThe first character in an XPath expression determines the point at which it should start in the XML tree. Statements beginning with a forward slash (/) are considered absolute. No slash indicates a relative reference. An example of a relative reference is: CD/* This statement begins the search at the current reference point. That means if the example occurred within a group of statements the reference point left by the previous statement would be utilized. A noted earlier, double forward slashes (//) retrieve every matching element regardless of location in the document. Context and ParentTo select current and parent elements, XPath recognizes the dot notation commonly used to navigate directories. Use a single period (.) to select the current node and use double periods (..) to return the parent of the current node. For example, to retrieve all child nodes of the parent of the current node, use: ../* Therefore, to access all CDs from the sample XML, use the following expression: /CATALOG/CD/.. You could also access all the CD tittles released in 1988 using the following: /CATALOG/CD/TITLE[../YEAR=1988] The .. is used to navigate up the tree of elements to find the YEAR element at the same level as the TITLE, where it is then tested for a match against "1988". You could also use // in this case, but if the element YEAR is used elsewhere in the XML document, you may get erroneous results. XPath is an extremely powerful standard when combined with RTF templates allowing you to use conditional formatting and filtering in your template. Namespace SupportIf your XML data contains namespaces, you must declare them in the template prior to referencing the namespace in a placeholder. Declare the namespace in the template using either the basic RTF method or in a form field. Enter the following syntax: <?namespace:namespace name= namespace url?> For example: <?namespace:fsg=http://www.oracle.com/fsg/2002-30-20/?> Once declared, you can use the namespace in the placeholder markup, for example: <?fsg:ReportName?> Using the Context CommandsThe BI Publisher syntax is simplified XSL instructions. This syntax, along with any native XSL commands you may use in your template, is converted to XSL-FO when you upload the template to the Template Manager. The placement of these instructions within the converted stylesheet determines the behavior of your template. BI Publisher's RTF processor places these instructions within the XSL-FO stylesheet according to the most common context. However, sometimes you need to define the context of the instructions differently to create a specific behavior. To support this requirement, BI Publisher provides a set of context commands that allow you to define the context (or placement) of the processing instructions. For example, using context commands, you can:
You can specify a context for both processing commands using the BI Publisher syntax and those using native XSL.
BI Publisher supports the following context types:
The following table shows the default context for the BI Publisher commands:
Using XSL ElementsYou can use any XSL element in your template by inserting the XSL syntax into a form field. If you are using the basic RTF method, you cannot insert XSL syntax directly into your template. BI Publisher has extended the following XSL elements for use in RTF templates. To use these in a basic-method RTF template, you must use the BI Publisher Tag form of the XSL element. If you are using form fields, use either option. Apply a Template RuleUse this element to apply a template rule to the current element's child nodes. XSL Syntax: <xsl:apply-templates select="name"> BI Publisher Tag: <?apply:name?> This function applies to <xsl:template-match="n"> where n is the element name. Copy the Current NodeUse this element to create a copy of the current node. XSL Syntax: <xsl:copy-of select="name"> BI Publisher Tag: <?copy-of:name?> Call TemplateUse this element to call a named template to be inserted into or applied to the current template. For example, use this feature to render a table multiple times. XSL Syntax: <xsl:call-template name="name"> BI Publisher Tag: <?call-template:name?> Template DeclarationUse this element to apply a set of rules when a specified node is matched. XSL Syntax: <xsl:template name="name"> BI Publisher Tag: <?template:name?> Variable DeclarationUse this element to declare a local or global variable. XSL Syntax: <xsl:variable name="name"> BI Publisher Tag: <?variable:name?> Example: <xsl:variable name="color" select="'red'"/> Assigns the value "red" to the "color" variable. The variable can then be referenced in the template. Import StylesheetUse this element to import the contents of one style sheet into another. Note: An imported style sheet has lower precedence than the importing style sheet. XSL Syntax: <xsl:import href="url"> BI Publisher Tag: <?import:url?> Define the Root Element of the StylesheetThis and the <xsl:stylesheet> element are completely synonymous elements. Both are used to define the root element of the style sheet. Note: An included style sheet has the same precedence as the including style sheet. XSL Syntax: <xsl:stylesheet xmlns:x="url"> BI Publisher Tag: <?namespace:x=url?> Note: The namespace must be declared in the template. See Namespace Support. Native XSL Number FormattingThe native XSL format-number function takes the basic format: format-number(number,format,[decimalformat])
Using FO ElementsYou can use the native FO syntax inside the Microsoft Word form fields. For more information on XSL-FO see the W3C Website at http://www.w3.org/2002/08/XSLFOsummary.html The full list of FO elements supported by BI Publisher can be found in the Appendix: Supported XSL-FO Elements. Copyright © 2005, 2006, Oracle. All rights reserved. When you export from Access into Word The resultant file is in what format?When you export an object from Access to Word, Access creates a file in the PDF format. Rich Text Format (RTF) is a format that enables documents created in one software application to be opened with a different software application.
On which tab in Access will you find buttons for exporting data?To export data from Access, first select the table or other database object to export in the Navigation Pane. Then click the “External Data” tab in the Ribbon. Then click the button in the “Export” button group for the file format to which to export the object.
Which database object is used to extract a subset of data from a database?Which database object is used to extract a subset of data from a database? A database query is a way of retrieving a particular subset of data that matches certain criteria.
Which of the following is a file format that is designed for exchanging data online?XML is a widely used format for data exchange because it gives good opportunities to keep the structure in the data and the way files are built on, and allows developers to write parts of the documentation in with the data without interfering with the reading of them.
|