<?xml version="1.0"?>
<!-- ========================================================= -->
<!--                                                           -->
<!-- (c) 2003, RenderX.                                        -->
<!--                                                           -->
<!-- Authors: Alexander Peshkov <peshkov@renderx.com>          -->
<!--                                                           -->
<!-- ========================================================= -->

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                              xmlns:fo="http://www.w3.org/1999/XSL/Format">
    
<!-- ========================================================= -->
<!-- This stylesheet is aimed to test Codabar barcode          -->
<!-- generator implemented in XSLT (codabar.xsl). Stylesheet   -->
<!-- creates XSL FO document based on an appropriate XML       -->
<!-- input, for every barcode entry in this XML it calls named -->
<!-- template to create SVG representation of Codabar barcode. -->
<!--                                                           -->
<!-- For more details please refer to the documentation found  -->
<!-- inside of the codabar.xsl stylesheet.                     -->
<!--                                                           -->
<!-- ========================================================= -->

    <!-- Import barcode generator templates -->
    <xsl:import href="../codabar.xsl"/>
    
    <xsl:output method="xml" indent="yes"/>	
    
    <xsl:template match="/">
      <fo:root font-family="Times" font-size="10pt">
	  <fo:layout-master-set>
	    <fo:simple-page-master master-name="barcodes-page">
		  <fo:region-body margin="0.5in" border="0.25pt solid silver" padding="10pt"/>
		</fo:simple-page-master>
	  </fo:layout-master-set>
	  <fo:page-sequence master-reference="barcodes-page">
	    <fo:flow flow-name="xsl-region-body">
          <xsl:apply-templates/>
 		</fo:flow>
	  </fo:page-sequence>
       </fo:root>
     </xsl:template>
	
     <xsl:template match="doc">
      <fo:block text-align="center" font-family="Helvetica" font-size="16pt" font-weight="bold">
        <xsl:value-of select="@title"/>
      </fo:block>
      <xsl:apply-templates/>
    </xsl:template>

    <xsl:template match="para">
      <fo:block text-indent="16pt"><xsl:apply-templates/></fo:block>
    </xsl:template>

    <xsl:template match="barcodes">
      <fo:table space-before="16pt">
        <fo:table-column column-width="70mm" column-number="1"/>
        <fo:table-column column-width="proportional-column-width(1)" column-number="2"/>
        <fo:table-body>
          <xsl:for-each select="barcode">
            <fo:table-row>
             <fo:table-cell column-number="1" border="thin solid black" text-align="center">
               <xsl:apply-templates select="." mode="draw"/>
             </fo:table-cell>
             <fo:table-cell column-number="2" border="thin solid black" padding="6pt">
               <xsl:apply-templates select="." mode="describe"/>
             </fo:table-cell>
            </fo:table-row>
          </xsl:for-each>
        </fo:table-body>
      </fo:table>
    </xsl:template>

	<!-- This template call barcode generator to create SVG representation of Codabar barcode -->
	<xsl:template match="barcode" mode="draw">
	  <fo:block>
	    <fo:instream-foreign-object content-width="100%" content-height="100%">
	      <xsl:call-template name="barcode-codabar">
	        <xsl:with-param name="value" select="@value"/>
	        <xsl:with-param name="start" select="@start"/>
	        <xsl:with-param name="stop" select="@stop"/>
	      </xsl:call-template>
	    </fo:instream-foreign-object>
	  </fo:block>
	</xsl:template>

	<xsl:template match="barcode" mode="describe">
	  <fo:block font-weight="bold">Barcode value: <xsl:value-of select="@value"/></fo:block>
	  <xsl:if test="@start!=''"><fo:block font-weight="bold">Start character: '<xsl:value-of select="@start"/>'</fo:block></xsl:if>
	  <xsl:if test="@stop!=''"><fo:block font-weight="bold">Stop character: '<xsl:value-of select="@stop"/>'</fo:block></xsl:if>
	  <fo:block space-before="6pt">
	    <xsl:value-of select="description"/>
	  </fo:block>
	</xsl:template>


</xsl:stylesheet>