Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2013, 01:39 AM
Registered User
 
Join Date: Jul 2013
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Duplicate output of Strong tag in nested list Help

This is the XML:
Code:
<Condition>
    <ol>
        <li><strong>Duty of Care:</strong> The [Tenancy Lookup] has the responsibility for a duty of care, for the land. This duty of care includes taking al reasonable steps to do the following in relation to the land:-
            <ol style="list-style-type: lower-alpha">
                <li>avoid causing or contributing to land salinity that -
                    <ol style="list-style-type: lower-roman">
                        <li>reduces its productivity; or</li>
                        <li>damages any other land;</li>
                    </ol>
                </li>
            </ol>
        </li>
    </ol>
</Condition>
This is the XSLT:

Code:
<xsl:template match="ol">

        <!-- Template parameter that specifies level of indentation. Set to 1 by default - if not specified. -->
        <xsl:param name="levelNumber">1</xsl:param>
        <xsl:param name="paragraphDepth"/>
        <xsl:param name="listDepth"/>
        <xsl:variable name="nodeNameTop" select="name()"/>
        <xsl:message>
            Node Name Top Level: <xsl:value-of select="$nodeNameTop"/>
        </xsl:message>
        <!-- This varibale allows to start from any element in the list, eg. numbered lists can start from 7 not 1. -->
        <xsl:variable name="format" select="@style"/>
        <fo:list-block>
            <xsl:for-each select="*">
                <xsl:variable name="nodeName" select="name()"/>
                <xsl:message>
                    Node Name for each: <xsl:value-of select="$nodeName"/>
                </xsl:message>
                <!-- If current item is a list item -->
                <xsl:if test="$nodeName = 'li'">
                    <fo:list-item>
                        <!--Call the lineItem template to decide the label format and indent-->
                        <xsl:call-template name="lineItemList">
                            <xsl:with-param name="numberFormat" select="$format"/>
                            <xsl:with-param name="levelNumber" select="$levelNumber"/>
                            <xsl:with-param name="levelStartIndent" select="number($indentSize) * number(number($levelNumber) - 1)"/>
                        </xsl:call-template>

                        <xsl:variable name="indentValueOL" select="number($indentSize)  * number($levelNumber) - 15"/>
                        <fo:list-item-body end-indent="0pt" start-indent="{$indentValueOL}pt">
                            <fo:block text-align="start" text-indent="0pt">
                                <!--<xsl:apply-templates Exclude child OL elements>-->
                                <xsl:apply-templates select="@* | node()[not(self::ol)]">
                                    <xsl:with-param name="levelNumber" select="number($levelNumber) +1"/>
                                    <xsl:with-param name="paragraphDepth" select="number($paragraphDepth) + 1"/>
                                </xsl:apply-templates>
                            </fo:block>
                            <!--Here we need to check for nested OL Lists-->
                            <xsl:if test="ol">
                                <xsl:message>
                                Nested OL
                                </xsl:message>
                                <xsl:apply-templates>
                                    <!--Paragraphdepth is not being set -->
                                    <xsl:with-param name="listDepth" select="number($listDepth) + 1"/>
                                    <xsl:with-param name="levelNumber" select="number($levelNumber) + 1"/>
                                    <xsl:with-param name="paragraphDepth" select="number($paragraphDepth) + 1"/>
                                </xsl:apply-templates>
                                <!--DEBUG-->
                            </xsl:if>


                        </fo:list-item-body>
                    </fo:list-item>
                </xsl:if>

                <!-- If current item is not a list item -->
                <xsl:if test="not($nodeName = 'li')">
                    <fo:list-item>
                        <fo:list-item-label>
                            <fo:block></fo:block>
                        </fo:list-item-label>
                        <fo:list-item-body>
                            <xsl:apply-templates>
                                <!-- Need to pass an incremeted indent as a parameter in case, this item is actually a nested list. -->
                                <xsl:with-param name="levelNumber" select="number($levelNumber) +1"/>
                                <xsl:with-param name="paragraphDepth" select="number($paragraphDepth) + 1"/>
                            </xsl:apply-templates>
                        </fo:list-item-body>
                    </fo:list-item>
                </xsl:if>
            </xsl:for-each>
        </fo:list-block>
    </xsl:template>
This is the Output NOTICE THE DUPLICATE Duty of Care that is not in the XML :
Code:
Code:
Description: Test description 1
1. Duty of Care: The [Tenancy Lookup] has the responsibility for a duty of care, for the land. This duty of
care includes taking al reasonable steps to do the following in relation to the land:-
Duty of Care:
a. avoid causing or contributing to land salinity that -
i. reduces its productivity; or
ii. damages any other land;

This is the strong Tag:
Code:
<xsl:template match="strong">
        <xsl:param name="paragraphDepth"/>
        <fo:inline font-weight="bold">
            <xsl:apply-templates>
                <xsl:with-param name="paragraphDepth" select="number($paragraphDepth) + 1"/>
            </xsl:apply-templates>
        </fo:inline>
    </xsl:template>
 
Old July 15th, 2013, 03:12 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Your basic mistake is to try and write this in "pull style" using xsl:for-each, xsl:if, and xsl:call-template. This is not the XSLT way of doing things, and its deficiencies become strongly apparent when you are handling mixed content, as here.

Read about template rules and xsl:apply-templates, and rewrite your code to use them. The solution will fall into place.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested List duplicate output of strong tag, going crazy Laza XSLT 0 July 15th, 2013 12:54 AM
How to Match Nested List Tag rangeshram XSLT 11 December 8th, 2009 08:59 AM
How to make a nested list tag that is valid? chobo2 CSS Cascading Style Sheets 1 April 21st, 2009 04:07 AM
remove duplicate text in an output html element mrame XSLT 1 June 20th, 2008 01:41 AM
Trying to output a tag within a tag jaucourt XSLT 3 January 12th, 2005 11:57 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.