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 23rd, 2008, 05:57 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 291
Thanks: 9
Thanked 29 Times in 29 Posts
Default finding the correct rows

Hi,
I have table with rows as specified below. The main key is <TL1Position> value and <TL1Commands> value. If two rows contain same <TL1Position> value but any one containing the value for <TL1Commands cmdType = "Create"> as M, then that <TL1Attribute> value should be shown.

<rattrow attrfield = "1">
<rattcell><TL1Instance>0001</TL1Instance></rattcell>
<rattcell><TL1Position>1</TL1Position></rattcell>
<rattcell><TL1Attribute attrType = "Positional">AID</TL1Attribute></rattcell>
<rattcell><TL1Commands cmdType = "Create">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Modify">Mgr</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Delete">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Remove">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Restore">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveIn">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveOut">M</TL1Commands></rattcell>
</rattrow>
<rattrow attrfield = "1">
<rattcell><TL1Instance>0001a</TL1Instance></rattcell>
<rattcell><TL1Position>1</TL1Position></rattcell>
<rattcell><TL1Attribute attrType = "Positional">AID</TL1Attribute></rattcell>
<rattcell><TL1Commands cmdType = "Create">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Modify">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Delete">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Remove">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Restore">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveIn">Ogr</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveOut">N</TL1Commands></rattcell>
</rattrow>
<rattrow attrfield = "1">
<rattcell><TL1Instance>0002</TL1Instance></rattcell>
<rattcell><TL1Position>2</TL1Position></rattcell>
<rattcell><TL1Attribute attrType = "Positional">AID</TL1Attribute></rattcell>
<rattcell><TL1Commands cmdType = "Create">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Modify">Mgr</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Delete">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Remove">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Restore">M</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveIn">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveOut">M</TL1Commands></rattcell>
</rattrow>
<rattrow attrfield = "1">
<rattcell><TL1Instance>0002a</TL1Instance></rattcell>
<rattcell><TL1Position>2</TL1Position></rattcell>
<rattcell><TL1Attribute attrType = "Positional">AID</TL1Attribute></rattcell>
<rattcell><TL1Commands cmdType = "Create">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Modify">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Delete">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Remove">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "Restore">N</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveIn">Ogr</TL1Commands></rattcell>
<rattcell><TL1Commands cmdType = "RetrieveOut">N</TL1Commands></rattcell>
</rattrow>

XSL:

<xsl:template match="rattrow[.//TL1Attribute]" mode="positional">
        <xsl:param name="tl1c"/>
        <xsl:variable name="currRow" select="."/>
    <xsl:variable name="check4">
        <xsl:for-each select="$currRow">

            <xsl:choose>
                        <xsl:when test="$tl1c = 'Retrieve'">
                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType='RetrieveIn'], '^[O|Y].*$')]">
                                <xsl:text>[&lt;</xsl:text>
                                <xsl:value-of select=".//TL1Attribute"/>
                                <xsl:text>&gt;]</xsl:text>
                            </xsl:for-each>

                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType='RetrieveIn'], '^M.*$')]">
                                <xsl:text>&lt;</xsl:text>
                                <xsl:value-of select="$currRow//TL1Attribute"/>
                                <xsl:text>&gt;</xsl:text>
                            </xsl:for-each>
                        </xsl:when>

                        <xsl:when test="$tl1c = 'Read'">
                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType='ReadIn'], '^[O|Y].*$')]">
                                <xsl:text>[&lt;</xsl:text>
                                <xsl:value-of select="$currRow//TL1Attribute"/>
                                <xsl:text>&gt;]</xsl:text>
                            </xsl:for-each>

                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType='ReadIn'], '^M.*$')]">
                                <xsl:text>&lt;</xsl:text>
                                <xsl:value-of select="$currRow//TL1Attribute"/>
                                <xsl:text>&gt;</xsl:text>
                            </xsl:for-each>
                        </xsl:when>

                        <xsl:otherwise>
                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType=$tl1c], '^[O|Y].*$')]">
                                <xsl:text>[&lt;</xsl:text>
                                <xsl:value-of select="$currRow//TL1Attribute"/>
                                <xsl:text>&gt;]</xsl:text>
                            </xsl:for-each>

                            <xsl:for-each
                                select=".[matches($currRow//TL1Commands[@cmdType=$tl1c], '^M.*$')]">
                                <xsl:text>&lt;</xsl:text>
                                <xsl:value-of select="$currRow//TL1Attribute"/>
                                <xsl:text>&gt;</xsl:text>
                            </xsl:for-each>
                            <xsl:text>,</xsl:text>
                        </xsl:otherwise>
                    </xsl:choose>
                  </xsl:for-each>
                  </xsl:variable>
                  <xsl:value-of select="$check4"/>
    </xsl:template>


__________________
Rummy





Similar Threads
Thread Thread Starter Forum Replies Last Post
move next rows in DataGrid < > prop. not correct fbailey ASP.NET 1.0 and 1.1 Basics 3 September 5th, 2007 10:17 AM
Is it correct like this ? tunisiano C# 1 March 7th, 2007 12:22 PM
Finding matching rows on two worksheets Wire323 Excel VBA 0 April 13th, 2006 12:11 AM
Limit rows returned and next rows minhpx General .NET 1 August 12th, 2004 06:25 AM
Automatically Finding and Deleting Blank rows Romulus Excel VBA 3 October 18th, 2003 09:04 PM





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