Wednesday, 1 July 2015

XSL FO File


XSL FO file:-
If we are having HTML tags and that needs to be converted accordingly in oracle ebs, we need to create the xsl file and import that file in the rtf.

<?xml version='1.0' encoding='utf-8'?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:fo="http://www.w3.org/1999/XSL/Format" version="1.0">
<xsl:output method="xml" encoding="UTF-8"/>
<!-- CUSTOMIZE html->fo for Rich Text Editor-->
<!-- elements -->
<xsl:template match="BLOCKQUOTE">
 <fo:block start-indent="0.25in">
 <xsl:apply-templates select="*|text()"/>
 </fo:block>
</xsl:template>
<xsl:template match="BLOCKQUOTE">
 <fo:block start-indent="0.25in">
 <xsl:apply-templates select="*|text()"/>
 </fo:block>
</xsl:template>
<xsl:template match="P|p">
 <fo:block white-space-collapse="false" padding-bottom="3pt" linefeed-treatment="preserve">
  <xsl:apply-templates select="text()|*|@*"/>
 </fo:block>
</xsl:template>
<xsl:template match="ol|OL">
  <fo:list-block provisional-distance-between-starts="1cm"
    provisional-label-separation="0.5cm">
    <xsl:attribute name="space-after">
      <xsl:choose>
        <xsl:when test="ancestor::ul or ancestor::ol">
          <xsl:text>0pt</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>12pt</xsl:text>
          </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <xsl:attribute name="start-indent">
      <xsl:variable name="ancestors">
        <xsl:choose>
          <xsl:when test="count(ancestor::ol) or count(ancestor::ul)">
            <xsl:value-of select="1 +
                                  (count(ancestor::ol) +
                                   count(ancestor::ul)) *
                                  1.25"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>1</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:value-of select="concat($ancestors, 'cm')"/>
    </xsl:attribute>
    <xsl:apply-templates select="*"/>
  </fo:list-block>
</xsl:template>

<xsl:template match="ol/li|OL/LI">
  <fo:list-item>
    <fo:list-item-label end-indent="label-end()">
      <fo:block>
        <xsl:variable name="value-attr">
          <xsl:choose>
            <xsl:when test="../@start">
              <xsl:number value="position() + ../@start - 1"/>
            </xsl:when>
            <xsl:otherwise>
              <xsl:number value="position()"/>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:variable>
        <xsl:choose>
          <xsl:when test="../@type='i'">
            <xsl:number value="$value-attr" format="i. "/>
          </xsl:when>
          <xsl:when test="../@type='I'">
            <xsl:number value="$value-attr" format="I. "/>
          </xsl:when>
          <xsl:when test="../@type='a'">
            <xsl:number value="$value-attr" format="a. "/>
          </xsl:when>
          <xsl:when test="../@type='A'">
            <xsl:number value="$value-attr" format="A. "/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:number value="$value-attr" format="1. "/>
          </xsl:otherwise>
        </xsl:choose>
      </fo:block>
    </fo:list-item-label>
    <fo:list-item-body start-indent="body-start()">
      <fo:block>
        <xsl:apply-templates select="*|text()"/>
      </fo:block>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>

<xsl:template match="table">
  <fo:table table-layout="fixed">
    <xsl:choose>
      <xsl:when test="@cols">
        <xsl:call-template name="build-columns">
          <xsl:with-param name="cols"
            select="concat(@cols, ' ')"/>
        </xsl:call-template>
      </xsl:when>
      <xsl:otherwise>
        <fo:table-column column-width="200pt"/>
      </xsl:otherwise>
    </xsl:choose>
    <fo:table-body>
      <xsl:apply-templates select="*"/>
    </fo:table-body>
  </fo:table>
</xsl:template>

<xsl:template name="build-columns">
  <xsl:param name="cols"/>
    <xsl:if test="string-length(normalize-space($cols))">
    <xsl:variable name="next-col">
      <xsl:value-of select="substring-before($cols, ' ')"/>
    </xsl:variable>
    <xsl:variable name="remaining-cols">
      <xsl:value-of select="substring-after($cols, ' ')"/>
    </xsl:variable>
    <xsl:choose>
      <xsl:when test="contains($next-col, 'pt')">
        <fo:table-column column-width="{$next-col}"/>
      </xsl:when>
      <xsl:when test="number($next-col) > 0">
        <fo:table-column column-width="{concat($next-col, 'pt')}"/>
      </xsl:when>
      <xsl:otherwise>
        <fo:table-column column-width="50pt"/>
      </xsl:otherwise>
    </xsl:choose>
        <xsl:call-template name="build-columns">
      <xsl:with-param name="cols" select="concat($remaining-cols, ' ')"/>
    </xsl:call-template>
  </xsl:if>
</xsl:template>

<xsl:template match="td">
  <fo:table-cell
    padding-start="3pt" padding-end="3pt"
    padding-before="3pt" padding-after="3pt">
    <xsl:if test="@colspan">
      <xsl:attribute name="number-columns-spanned">
        <xsl:value-of select="@colspan"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="@rowspan">
      <xsl:attribute name="number-rows-spanned">
        <xsl:value-of select="@rowspan"/>
      </xsl:attribute>
    </xsl:if>
    <xsl:if test="@border='1' or
                  ancestor::tr[@border='1'] or
                  ancestor::thead[@border='1'] or
                  ancestor::table[@border='1']">
      <xsl:attribute name="border-style">
        <xsl:text>solid</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="border-color">
        <xsl:text>black</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="border-width">
        <xsl:text>1pt</xsl:text>
      </xsl:attribute>
    </xsl:if>
    <xsl:variable name="align">
      <xsl:choose>
        <xsl:when test="@align">
          <xsl:choose>
            <xsl:when test="@align='center'">
              <xsl:text>center</xsl:text>
            </xsl:when>
            <xsl:when test="@align='right'">
              <xsl:text>end</xsl:text>
            </xsl:when>
            <xsl:when test="@align='justify'">
              <xsl:text>justify</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>start</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:when test="ancestor::tr[@align]">
          <xsl:choose>
            <xsl:when test="ancestor::tr/@align='center'">
              <xsl:text>center</xsl:text>
            </xsl:when>
            <xsl:when test="ancestor::tr/@align='right'">
              <xsl:text>end</xsl:text>
            </xsl:when>
            <xsl:when test="ancestor::tr/@align='justify'">
              <xsl:text>justify</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>start</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:when test="ancestor::thead">
          <xsl:text>center</xsl:text>
        </xsl:when>
        <xsl:when test="ancestor::table[@align]">
          <xsl:choose>
            <xsl:when test="ancestor::table/@align='center'">
              <xsl:text>center</xsl:text>
            </xsl:when>
            <xsl:when test="ancestor::table/@align='right'">
              <xsl:text>end</xsl:text>
            </xsl:when>
            <xsl:when test="ancestor::table/@align='justify'">
              <xsl:text>justify</xsl:text>
            </xsl:when>
            <xsl:otherwise>
              <xsl:text>start</xsl:text>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>start</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:variable>
    <fo:block text-align="{$align}">
      <xsl:apply-templates select="*|text()"/>
    </fo:block>
  </fo:table-cell>
</xsl:template>

<xsl:template match="tfoot">
  <xsl:apply-templates select="tr"/>
</xsl:template>

<xsl:template match="th">
  <fo:table-cell
    padding-start="3pt" padding-end="3pt"
    padding-before="3pt" padding-after="3pt">
    <xsl:if test="@border='1' or
                  ancestor::tr[@border='1'] or
                  ancestor::table[@border='1']">
      <xsl:attribute name="border-style">
        <xsl:text>solid</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="border-color">
        <xsl:text>black</xsl:text>
      </xsl:attribute>
      <xsl:attribute name="border-width">
        <xsl:text>1pt</xsl:text>
      </xsl:attribute>
    </xsl:if>
    <fo:block font-weight="bold" text-align="center">
      <xsl:apply-templates select="*|text()"/>
    </fo:block>
  </fo:table-cell>
</xsl:template>

<xsl:template match="thead">
  <xsl:apply-templates select="tr"/>
</xsl:template>

<xsl:template match="tr">
  <fo:table-row>
    <xsl:apply-templates select="*|text()"/>
  </fo:table-row>
</xsl:template>

<xsl:template match="ul|UL">
  <fo:list-block provisional-distance-between-starts="1cm"
    provisional-label-separation="0.5cm">
    <xsl:attribute name="space-after">
      <xsl:choose>
        <xsl:when test="ancestor::ul or ancestor::ol">
          <xsl:text>0pt</xsl:text>
        </xsl:when>
        <xsl:otherwise>
          <xsl:text>12pt</xsl:text>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:attribute>
    <xsl:attribute name="start-indent">
      <xsl:variable name="ancestors">
        <xsl:choose>
          <xsl:when test="count(ancestor::ol) or count(ancestor::ul)">
            <xsl:value-of select="1 +
                                  (count(ancestor::ol) +
                                   count(ancestor::ul)) *
                                  1.25"/>
          </xsl:when>
          <xsl:otherwise>
            <xsl:text>1</xsl:text>
          </xsl:otherwise>
        </xsl:choose>
      </xsl:variable>
      <xsl:value-of select="concat($ancestors, 'cm')"/>
    </xsl:attribute>
    <xsl:apply-templates select="*"/>
  </fo:list-block>
</xsl:template>

<xsl:template match="ul/li|UL/LI">
  <fo:list-item>
    <fo:list-item-label end-indent="label-end()">
      <fo:block>&#x2022;</fo:block>
    </fo:list-item-label>
    <fo:list-item-body start-indent="body-start()">
      <fo:block>
        <xsl:apply-templates select="*|text()"/>
      </fo:block>
    </fo:list-item-body>
  </fo:list-item>
</xsl:template>

<xsl:template match="HR|hr">
<fo:block text-align="justify">
<fo:leader leader-pattern="rule">
<xsl:apply-templates select="@*"/>
</fo:leader>
</fo:block>
</xsl:template>
<xsl:template match="BR|br">
<xsl:text>
</xsl:text>
</xsl:template>
<xsl:template match="STRONG|B|b">
<fo:inline font-weight="bold">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
<xsl:template match="EM|I|i">
<fo:inline font-style="italic">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>
<xsl:template match="U|u">
<fo:inline text-decoration="underline">
<xsl:apply-templates/>
</fo:inline>
</xsl:template>

<!-- attributes -->
<xsl:template match="@align">
<xsl:attribute name="text-align"><xsl:value-of select="."/></xsl:attribute>
</xsl:template>

<xsl:template match="@*">
</xsl:template>
</xsl:stylesheet>

Uploading PO Attachments from EBS to FTP Server

 create or replace PROCEDURE xx_upload_po_attachment(errbuff out varchar2, retcode out number)  IS CURSOR cur_new_attmt IS    select ponumbe...