Use Global XSLT

Top Previous Topic Next Topic  Print this topic

Overview:

XSLT (Extensible Stylesheet Language Transformations) is a declarative, XML-based language used for the transformation of XML documents.

The original document is not changed; rather, a new document is created based on the content of an existing one.

Global XSLT can be used and applied to xfd documents.

 

Solution:

Inserting Global XSLT

 

The Global XSLT button is located in the Template group, under the Review tab. After selecting it, the Global XSLT code dialog will be displayed.

 

 

Examples of Global XSLT usage

 

In the following examples, the xml file pictured below will be used:

 

company_xml

 

 

Example 1 Inserting a table depending on the "company" field's id and displaying the products used by the company.

 

 

<xsl:template match="company">

<xsl:if test="@id = 'A'">

<fo:block>

<fo:table border-collapse="collapse" width="100%" table-layout="fixed">

<fo:table-column column-width="proportional-column-width(30)" column-number="1"/>

<fo:table-column column-width="proportional-column-width(70)" column-number="2"/>

<fo:table-body>

<fo:table-row>

<fo:table-cell border="1pt solid black" padding="2pt"><fo:block><xsl:apply-templates/></fo:block>

</fo:table-cell>

<fo:table-cell border="1pt solid black" padding="2pt"><fo:block><xsl:if test="@prod1">

<fo:block>Product 1 is <xsl:value-of select="@prod1"/></fo:block>

</xsl:if>

</fo:block>

<fo:block>

<xsl:if test="@prod2">

<fo:block>Product 2 is <xsl:value-of select="@prod2"/></fo:block>

</xsl:if>

</fo:block>

</fo:table-cell>

</fo:table-row>

</fo:table-body>

</fo:table>

</fo:block>

</xsl:if>

</xsl:template>

 

 

Example 2 Inserting a barcode if the CompanyA's first product is "ProdA".

 

 

<xsl:template match="company">

<xsl:if test="@prod1 = 'ProdA'">

<fo:block>

<xf:barcode type="Code128" xf:value="Barcode for CompanyA" draw-text="true" rotation="0" fo:id="60F13C7D">

<xsl:attribute name="xf:value">

<xsl:value-of select="@prod1"/>

</xsl:attribute>

</xf:barcode>

</fo:block>

</xsl:if>

</xsl:template>

 

 

Example 3 Replace all "ProdA" values for "@prod1" with "ProductA".

 

 

<xsl:template name="string-replace-all">

<xsl:param name="text"/>

<xsl:param name="replace"/>

<xsl:param name="by"/>

<xsl:choose>

<xsl:when test="contains($text, $replace)">

<xsl:value-of select="substring-before($text,$replace)"/>

<xsl:value-of select="$by"/>

<xsl:call-template name="string-replace-all">

<xsl:with-param name="text" select="substring-after($text,$replace)"/>

<xsl:with-param name="replace" select="$replace"/>

<xsl:with-param name="by" select="$by"/>

</xsl:call-template>

</xsl:when>

<xsl:otherwise>

<xsl:value-of select="$text"/>

</xsl:otherwise>

</xsl:choose>

</xsl:template>

<xsl:template match="company">

<xsl:if test="@prod1">

<fo:block>

 

<xsl:call-template name="string-replace-all">

<xsl:with-param name="text" select="@prod1"/>

<xsl:with-param name="replace" select="'ProdA'"/>

<xsl:with-param name="by" select="'ProductA'"/>

</xsl:call-template></fo:block>

</xsl:if>

</xsl:template>