XSL:FO - How to decrement the bullet number using fo:list-block

XSL:FO - How to decrement the bullet number using fo:list-block

As per my knowledge we cannot change the value of xsl:variable once assigned. I tried that option as well. :frowning:

Interesting problem. The first thing I noticed was the wrong slash in the select. I don’t know why that didn’t choke on you, but I guess it was changing things so it would be the same as if you had simply done “Books”.

Using this for the XML file:

rajesh.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml-stylesheet type="text/xsl" href="rajesh.xsl"?>
<STUDY>
	<Books>
		<Category>Science</Category>
	</Books>
	<Books>
		<Category>Social</Category>
	</Books>
	<Books>
		<Note>Important</Note>
	</Books>
	<Books>
		<Category>Maths</Category>
	</Books>
	<Books>
		<Category>English</Category>
	</Books>
</STUDY>

and this for the XSL file:

rajesh.xsl

<xsl:stylesheet version="1.0"    
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns="http://www.w3.org/TR/REC-html40" >
<xsl:template match="STUDY">
<!--
	<xsl:for-each select="Books\\Category">	wrong slash
-->
	<xsl:for-each select="Books/Category | Books/Note">
		<fo:list-block space-before="5pt">
			<fo:list-item>
				<fo:list-item-label end-indent="label-end()">
					<fo:block start-indent="55pt" space-before="10pt">
	<xsl:if test="name() = 'Category'">
						<xsl:number value="position()" format=" 1. "/>
	</xsl:if>
						</fo:block>
				</fo:list-item-label>
				<fo:list-item-body start-indent="body-start()">
					<fo:block start-indent="80pt" wrap-option="wrap" space-before="10pt">
						<xsl:apply-templates/>
					</fo:block>
				</fo:list-item-body>
			</fo:list-item>
		</fo:list-block>
		<br />
	</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

Gives me in IE

1. Science
2. Social
Important
4. Maths
5. English

I think the solution may be to use the value attribute in number, giving it the value of a variable that’s incremented inside the if.

:d’oh: I saw the order of the words and missed the numbering :blush:

I have to go offline for a while but I’ll take a closer look and post back.

Sorry, but unless I’m missing something the output you’re getting is the output you want??

I want the output to be incremental 1, 2, 3, 4…
but the current output has 1, 2, 4, 5

Hi,

I am trying to count the specific nodes using a fo:list-block. I have an XML as below:

<STUDY>
<Books>
<Category>Science</Category>
</Books>
<Books>
<Category>Social</Category>
</Books>
<Books>
<Note>Important</Note>
</Books>
<Books>
<Category>Maths</Category>
</Books>
<Books>
<Category>English</Category>
</Books>
</STUDY>

The code I have used is as below:

<xsl:template match=“STUDY”>
<xsl:for-each select=“Books\Category”>
<fo:list-block space-before=“5pt”>
<fo:list-item>
<fo:list-item-label end-indent=“label-end()”>
<fo:block start-indent=“55pt” space-before=“10pt”>
<xsl:number format=“1.”/>
</fo:block>
</fo:list-item-label>
<fo:list-item-body start-indent=“body-start()”>
<fo:block start-indent=“80pt” wrap-option=“wrap” space-before=“10pt”>
<xsl:apply-templates/>
</fo:block>
</fo:list-item-body>
</fo:list-item>
</fo:list-block>
</xsl:for-each>
</xsl:template>

With the Above code, I am getting the following output:

  1. Science
  2. Social
    Important
  3. Maths
  4. English

I want to generate an HTML with the following output:

  1. Science
  2. Social
    Important
  3. Maths
  4. English

Perhaps you can show some of your code? Are you talking about something like

<fo:static-content flow-name="regaft">
<fo:block text-align="start">
  Page 
  <fo:page-number/> 
  of 
  <fo:page-number-citation ref-id="TheVeryLastPage"/>
</fo:block>
</fo:static-content>

I finally had some time to work on this some more and got it to work in IE.

Inside the :foreach I added a :choose and :when

	<xsl:choose>
		<xsl:when test="name() = 'Category'">

then your code but with :number having a level attribute of “any”
then another :when for “Note” but without the :number

I still don’t like the redundant :list-block code very much but I got tired of experimenting. Maybe you can clean it up some, but it will work in IE.

I couldn’t get the list to show vertical in Firefox. How did you manage that?
I know I can do it with PHP, VB or C++ but I seem to remember seeing a way to do it with just XML and XSL but I don’t remember how.