SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Bangalore
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

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

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

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Perhaps you can show some of your code? Are you talking about something like
    Code XML:
    <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>

  3. #3
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Bangalore
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    4. Maths
    5. English

    I want to generate an HTML with the following output:

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

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    Sorry, but unless I'm missing something the output you're getting is the output you want??

  5. #5
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Bangalore
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want the output to be incremental 1, 2, 3, 4..
    but the current output has 1, 2, 4, 5

  6. #6
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    :d'oh: I saw the order of the words and missed the numbering

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

  7. #7
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    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
    Code 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
    Code XML:
    <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
    Code:
    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.

  8. #8
    SitePoint Member
    Join Date
    Jul 2010
    Location
    Bangalore
    Posts
    9
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    As per my knowledge we cannot change the value of xsl:variable once assigned. I tried that option as well.

  9. #9
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,139
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    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
    Code XML:
    	<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.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •