Search code examples
xmlxsltxsl-fobi-publisher

Right align xml data while generating PDF using fo:list-block


I have number list in my XML input And I am able to align list body(text content) to align right, but numbers remain aligned to left. How can I align entire list including numbers/bullets to right, by default is comes to left. Any help or pointers is highly appreciated, Thanks.

Current output:

 Number list below
 1.                                                                 L List 1
 2.                                                                 R list 2

My expected output :

 Number list below
                                                                   1. L List 1
                                                                   2. R list 2

I have simplified xml data as below :

<p>Number list below</p>
      <ol>
         <li style="text-align: right;">L list 1</li>
         <li style="text-align: right;">R list 2</li>
      </ol>

My xslt code look like below:

<xsl:template match="LI|li">
	<fo:list-block>	
		<xsl:attribute name="text-align">
			<!--xsl:value-of select="end"/-->
			<xsl:text disable-output-escaping="yes">right</xsl:text>
		</xsl:attribute>		
		<fo:list-item>
			<fo:list-item-label end-indent="label-end()">
				<fo:block>
					<xsl:variable name="value-fetcher">
						<xsl:choose>
							<xsl:when test="../@start">
								<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
							</xsl:when>
							<xsl:otherwise>
								<xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
							</xsl:otherwise>
						</xsl:choose>
					</xsl:variable>
					<xsl:number value="$value-fetcher" format="1."/>					
				</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>
	</fo:list-block>
</xsl:template>


Solution

  • Thanks for the replies, are always useful.

    alignment achieved by below xslt:

    <xsl:template match="LI|li">
    <fo:block margin-left="36pt" text-align="right">
    	<fo:leader leader-pattern="space" leader-length="-18pt"/>
    	<fo:inline><xsl:variable name="value-fetcher">
                            <xsl:choose>
                                <xsl:when test="../@start">
                                    <xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI)+ ../@start"/>
                                </xsl:when>
                                <xsl:otherwise>
                                    <xsl:number value="count(preceding-sibling::li) + count(preceding-sibling::LI) + 1"/>
                                </xsl:otherwise>
                            </xsl:choose>
                        </xsl:variable>
                        <xsl:number value="$value-fetcher" format="1."/> 
    	</fo:inline>
    	<fo:inline>
    	<fo:leader leader-pattern="space" leader-length="18pt"/>
    	 <xsl:apply-templates select="text()"/>
    	</fo:inline>
    </fo:block>
    </xsl:template>