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 January 21st, 2005, 10:41 AM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default <xsl:choose> and <xsl:otherwise> problem

Hello,

I am creating a simple XSLT using the <xsl:choose> instruction to conditionally handle varying attributes for a <Para> tag in my file.

The test branching seems to work just fine, the problem is that the <xsl:otherwise> alwise fires, even when one of the other branches has already executed.

Here is the code snippet:
    <xsl:template match="Para">
        <p>
        <xsl:choose>
            <xsl:when test="@Justify='Center'">
                <center>
                    <xsl:value-of select="." />
                </center>
            </xsl:when>
            <xsl:when test="@FirstLineIndent='7'">
                <xsl:text> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</xsl:text>
                <xsl:value-of select="." />
            </xsl:when>
            <xsl:when test="@FirstLineIndent='13'">
                <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;
                </xsl:text>
                <xsl:value-of select="." />
            </xsl:when>
            <xsl:when test="@FirstLineIndent='19'">
                <xsl:text>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs p;&nbsp;&nbsp;&nbsp;
                                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n bsp;
                </xsl:text>
                <xsl:value-of select="." />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="." />
            </xsl:otherwise>
        </xsl:choose>
         </p>
      </xsl:template>


So in the example, after a <center> 'd paragraphs text is displayed correctly, the <xsl:otherwise> displays the text again, resulting in double output.

Thanks for any help with this.

Dan


 
Old January 21st, 2005, 11:36 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

How do you know that its the xsl:otherwise that's producing the text again? Could it not be coming from another template, or a default rule? I only ask because its extremely unlikely that your xsl processor is running the 'otherwise' condition as well as one of the 'when' conditions.

What processor are you using? Do you have access to a debugger that you can use to step through the transform?
 
Old January 21st, 2005, 11:43 AM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using the Altova XMLSpy 5.0 program and debugger to step through the XML file as the XSLT transformation is taking place.

After the <xsl:when test="@Justify='Center'"> is processed I can step through and watch the <xsl:choose> and each other <xsl:when> condition get evaluated. I then see the <xsl:otherwise> step being executed.

The duplicate output is coming from the otherwise statement, not from another template.

 
Old January 21st, 2005, 12:06 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Either your XSLT processor has a very strange bug indeed, or your diagnosis of the problem is wrong. Try it on another XSLT processor to see which is the case.



Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old January 21st, 2005, 01:56 PM
Authorized User
 
Join Date: Mar 2004
Posts: 20
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks to all for the posts. This is indeed a bug in the XML tool I am using, it was reported as fixed in the latest SP, but apparently still exists. This statement is working correctly in another XSLT processor.

Regards,
Dan






Similar Threads
Thread Thread Starter Forum Replies Last Post
embedded <xsl:element> into <xsl:with-param> petergoodman XSLT 2 July 9th, 2008 06:36 AM
Performance for <xsl:import> and <xsl:include> vikkiefd XSLT 2 April 16th, 2008 08:06 AM
<xsl:for-each> inside another <xsl:for-each> suersh79 XSLT 2 December 29th, 2006 01:24 AM
HELP: XSL -> HTML <select selected=true> jedbartlett XSLT 4 October 7th, 2004 11:16 PM
problem using <xsl:attribute> arvin XSLT 2 July 21st, 2003 03:13 AM





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