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 March 16th, 2007, 12:18 PM
Registered User
 
Join Date: Jan 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to northwind Send a message via Yahoo to northwind
Default XSLT HELP

Hi there i am writing an xslt but it has a repeating result/output which is not expected.

Please help me to debug the code. See code below

===============================================
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:variable name="count_package_disc"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='DISCONNECT']/isp/pacakge"/>
<xsl:variable name="count_package_inst"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='INSTALL']/isp/pacakge"/>

<xsl:variable name="disc_action"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='DISCONNECT']/isp/pacakge/action/text()"/>
<xsl:variable name="inst_action"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='INSTALL']/isp/pacakge/action/text()"/>

<xsl:variable name="disc_packid"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='DISCONNECT']/isp/pacakge/packageId/text()"/>
<xsl:variable name="inst_packid"
                select="//htcBusinessDoc/payload/htcBase/sites/site/lineOrder/lineItem[lineAction='INSTALL']/isp/pacakge/packageId/text()"/>

<xsl:template match="/">
    <xsl:choose>
    <xsl:when test="count($count_package_disc) = count($count_package_inst)">
        <xsl:for-each select="$disc_action">
             <xsl:for-each select="$inst_action">
                <xsl:if test="$disc_action = 'DISCON'">
                <xsl:if test="$inst_action = 'ADD'">
                   <xsl:if test="$disc_packid = $inst_packid">

                   <xsl:value-of select="/htcBusinessDoc/header/serviceAction"/>
                   <xsl:value-of select="/htcBusinessDoc/header/orderType"/>

                   </xsl:if>
                </xsl:if>
                </xsl:if>

           </xsl:for-each>
        </xsl:for-each>

        </xsl:when>
        <xsl:otherwise>
           Not PASSED
        </xsl:otherwise>
         </xsl:choose>
</xsl:template>

</xsl:stylesheet>
================================================== ==========

Writing Software Application is just setting instructions to the code and there is nothing impossible.
 
Old March 16th, 2007, 12:47 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm not sure why you find the repetition unexpected. When you do

        <xsl:for-each select="$disc_action">
             <xsl:for-each select="$inst_action">


you are processing all the inst_action elements repeatedly - you process them all for hte first disc_action, then again for the second, and so on. Then your condition

<xsl:if test="$disc_packid = $inst_packid">


uses variables whose values don't depend at all on the current nodes you are processing in the two for-each loops.

You don't want all these global variables, you want to select nodes relative to the context node.

Without knowing your data model I can't be more specific.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 16th, 2007, 03:25 PM
Registered User
 
Join Date: Jan 2007
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to northwind Send a message via Yahoo to northwind
Default

Hi Michael-

Here is the link of the xml,

http://rapidshare.com/files/21368172/M300793.xml

Thanks for your help.

Rommel

Writing Software Application is just setting instructions to the code and there is nothing impossible.
 
Old March 16th, 2007, 07:20 PM
Friend of Wrox
 
Join Date: Jul 2006
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Your best bet is to use the "reply to topic" and copy and paste your xml with the # (code)

bones






Similar Threads
Thread Thread Starter Forum Replies Last Post
Generating XSLT with XSLT stonis XSLT 3 April 1st, 2008 08:17 PM
General XSLT Questions in the XSLT Forum jminatel BOOK: XSLT 2.0 and XPath 2.0 Programmer's Reference, 4th Edition ISBN: 978-0-470-19274-0 0 March 31st, 2008 07:50 PM
Can XSLT read DTD/schema and Generate XSLT.. ROCXY XSLT 1 November 6th, 2006 09:39 AM
dynamic xslt -> xslt creation namespace problem jkmyoung XSLT 2 July 15th, 2006 12:42 AM
xslt with an xslt outputfile alleycat XSLT 4 February 20th, 2006 09:56 AM





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