Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 3rd, 2004, 12:56 PM
Registered User
 
Join Date: Dec 2004
Location: , , Canada.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default preceding-sibling behaviour

Hi Everyone,
I have a preceding-sibling if statement that is always evaluating true. I think it is getting stuck inside a nested node, and not searching the whole document. I am trying to avoid printing out rows with the same part number. My XML is below...


<Node Name="DCM Buhler">
<Shift Name="Night Shift">
    <DataType Name="Counters">
        <Identifier Name="Part Number" Value="772100">
            <Identifier Name="Die/Cavity" Value="#23">
                <Variable Name="DC Shot Counter">data</Variable>
                <Variable Name="DC Parts Cast">data</Variable>
                <Variable Name="DC Parts Scrapped Auto">data</Variable>
            </Identifier>
        </Identifier>
        <Identifier Name="Part Number" Value="721115">
            <Identifier Name="Die/Cavity">
                <Variable Name="DC Shot Counter">data</Variable>
                <Variable Name="DC Parts Cast">data</Variable>
                <Variable Name="DC Parts Scrapped Auto">data</Variable>
            </Identifier>
        </Identifier>
    </DataType>
</Shift>
<Shift Name="Morning Shift">
    <DataType Name="Counters">
        <Identifier Name="Part Number" Value="772100">
            <Identifier Name="Die/Cavity" Value="#23">
                <Variable Name="DC Shot Counter" Type="1" Unit="cts">data</Variable>
                    <Variable Name="DC Parts Cast">data</Variable>
                    <Variable Name="DC Parts Scrapped Auto">data</Variable>
                </Identifier>
            </Identifier>
            <Identifier Name="Part Number" Value="721115">
                <Identifier Name="Die/Cavity" Value="14" PartsPerShot="1" Duration="1378">
                    <Variable Name="DC Shot Counter">data</Variable>
                    <Variable Name="DC Parts Cast">data</Variable>
                    <Variable Name="DC Parts Scrapped Auto">data</Variable>
                </Identifier>
            </Identifier>
        </DataType>
    </Shift>
etc...


The XSL I'm using is as follows...

<xsl:for-each select="//Node">
    <xsl:variable name="Cell" select="@Name"/>
    <xsl:for-each select="//Node[@Name=$Cell]/Shift/DataType[@Name='Counters']/Identifier[@Name = 'Part Number' and ./Identifier/Variable/VRD[@Value != '' and @Value != '0']]">

        <xsl:sort data-type="text" select="@Value"/>
        <xsl:variable name="PartNo" select="@Value"/>

        <xsl:if test="not(preceding-sibling::node()/@Value = $PartNo)">

            <xsl:for-each select="Identifier[@Name = 'Die/Cavity' and ./Variable/VRD[@Value != '' and @Value != '0']]">
                <xsl:variable name="DieCavity" select="@Value"/>
                <xsl:variable name="PartsCast" select="sum(//Node[@Name=$Cell]/Shift/DataType[@Name='Counters']/Identifier[@Name='Part Number' and @Value=$PartNo]/Identifier[@Name='Die/Cavity' and @Value=$DieCavity]/Variable[@Name = 'DC Parts Cast']/VRD[@Value != '']/@Value)"/>
                <xsl:variable name="PartsScrapped" select="sum(//Node[@Name=$Cell]/Shift/DataType[@Name='Counters']/Identifier[@Name='Part Number' and @Value=$PartNo]/Identifier[@Name='Die/Cavity' and @Value=$DieCavity]//Variable[@Name = 'DC Parts Scrapped Auto' or @Name = 'DC Parts Scrapped Operator']/VRD[@Value != '']/@Value)"/>
                <xsl:variable name="PotentialCast" select="(ancestor::node()/@GPURate) * (ancestor-or-self::node()/@Duration) div 60"/>

                <!-- CREATE TABLE HERE.../>

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

As you can probably tell by my code, I'm pretty new to this stuff.

Anybody have any ideas? I have been stumped for hours now!

Thanks a lot!





Andrew
Reply With Quote
  #2 (permalink)  
Old December 3rd, 2004, 01:14 PM
joefawcett's Avatar
Wrox Author
Points: 9,763, Level: 42
Points: 9,763, Level: 42 Points: 9,763, Level: 42 Points: 9,763, Level: 42
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Exeter, , United Kingdom.
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Too late on a Friday for an in depth look I'm afraid. However you may find Muenchian Grouping will help here.

--

Joe (Microsoft MVP - XML)
Reply With Quote
  #3 (permalink)  
Old December 3rd, 2004, 01:32 PM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

<xsl:if test="not(preceding-sibling::node()/@Value = $PartNo)">
This only tests if the directly preceding sibling (one node) does not have the same part number.

What you want could be:
<xsl:if test="not(preceding-sibling::*[@Value = $PartNo])">
Test if any of the preceding-siblings have the same value..
WARNING!: This only tests nodes within the same Dataype. Did you want to test all nodes, eg have the Night Shift match up with the morning shift?
yeah, I think Muenchian grouping would make it easier too.

---
what are you going for as a final result? seems a lot of your x-path's could use simplifying, eg. "./" is always redundant.
Reply With Quote
  #4 (permalink)  
Old December 3rd, 2004, 02:32 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

This is WRONG!

 <xsl:if test="not(preceding-sibling::node()/@Value = $PartNo)">
This only tests if the directly preceding sibling (one node) does not have the same part number.

What you want could be:
<xsl:if test="not(preceding-sibling::*[@Value = $PartNo])">
Test if any of the preceding-siblings have the same value..

The first example tests all preceding-sibling nodes (all nodes with the same parent, that precede the context node). The second example only tests preceding-sibling element nodes.

Michael Kay

Michael Kay
http://www.saxonica.com/
Reply With Quote
  #5 (permalink)  
Old December 3rd, 2004, 02:37 PM
mhkay's Avatar
Wrox Author
Points: 18,481, Level: 59
Points: 18,481, Level: 59 Points: 18,481, Level: 59 Points: 18,481, Level: 59
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,960
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In this:

<xsl:for-each select="//Node[@Name=$Cell]/Shift/DataType[@Name='Counters']/Identifier[@Name = 'Part Number' and ./Identifier/Variable/VRD[@Value != '' and @Value != '0']]">

You will get an empty node-set if there are no VRD elements in your data. I don't see any VRD elements in your data.



Michael Kay
http://www.saxonica.com/
Reply With Quote
  #6 (permalink)  
Old December 3rd, 2004, 02:50 PM
Registered User
 
Join Date: Dec 2004
Location: , , Canada.
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for all your help guys. Is there a way to do it that will find all of the identical Part No.'s regardless of DataType and Shift? All I'm interested in is duplicate Part No.'s under the "Cell" Node.

P.S. Michael, I have VRD's in my real data, I just didn't include them here. Sorry for the confusion!

Andrew
Reply With Quote
  #7 (permalink)  
Old December 3rd, 2004, 03:24 PM
Authorized User
 
Join Date: Nov 2004
Location: , , .
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

So let me see if I'm summarizing this right:
XPath of grouping field: "/Node/Shift/DataType[@Name='Counters']/Identifier[@Name = 'Part Number']/@Value"
Restrictions: Identifier has Variable/VRD/@Value with non-zero, non-empty value.
Grouping by: Identifiers? first level?

So placing these into a key:
<xsl:key name="part-by-value" match="Identifier" use="@Value" />
selecting each group:
<xsl:for-each select="/Node/Shift/DataType[@Name='Counters']/Identifier[@Name = 'Part Number' and Identifier/Variable/VRD[@Value != '' and @Value != '0']][count(.|key('part-by-value',@Value)[1])=1]">

now within that group did you want to select all of the nodes with the same value, or just the first one?
Selecting each node with the same value:
<xsl:for-each select="key('part-by-value',@Value)">

WARNING: since you have Identifier's inside Identifier's, you may run into conflicts if any of the values of the inside identifiers has the same value as an outside identifiers value. What key('part-by-value' @Value) does, is selects all Identfier nodes with the same Value, regardless of level.



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Using preceding-sibling mcanne98 Infopath 0 September 11th, 2008 11:09 PM
Inproper behaviour of preceding-sibling ramuis78 XSLT 7 June 12th, 2006 01:54 PM
preceding-sibling descendant xaun XSLT 3 February 28th, 2006 02:48 PM
preceding-sibling jonesyp XSLT 2 November 22nd, 2005 12:29 PM
preceding-sibling after sort rushman XSLT 3 January 18th, 2005 11:08 AM



All times are GMT -4. The time now is 11:43 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.