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 October 30th, 2004, 11:12 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Need Help on Filtering duplicated data

I have following xml data

<?xml version="1.0" encoding="UTF-8"?>
<datas>
<data>
<item id="9191" title="First">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PA</entry>
</datafield>
</item>
<item id="9695">
<datafield>
<label>item_type_code</label>
<entry>OE</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>OEE</entry>
</datafield>

</item>
</data>
<data>
<item id="9291" title="Second">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="1086">
<datafield>
<label>item_type_code</label>
<entry>PP</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PPA</entry>
</datafield>

</item>
</data>
<data>
<item id="9993" title="Four">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="9983" title="Fifty">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>

<item id="8987">
<datafield>
<label>item_type_code</label>
<entry>OE</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>OEE</entry>
</datafield>

</item>
</data>
<data>
<item id="9993" title="Four">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="9987" title="Six">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="9687">
<datafield>
<label>item_type_code</label>
<entry>OE</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>OEE</entry>
</datafield>
</item>
</data>
<data>
<item id="9168" title="Sevent">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="9087" title="Ten">
<datafield>
<label>item_type_code</label>
<entry>PA</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>PAA</entry>
</datafield>
</item>
<item id="9487">
<datafield>
<label>item_type_code</label>
<entry>OE</entry>
</datafield>
<datafield>
<label>item_type_description</label>
<entry>OEE</entry>
</datafield>
</item>
</data>
</datas>



And my xsl as following

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xml:space="default">

<xsl:template match="/">
<xsl:apply-templates select="//item" mode="passage"/>
</xsl:template>
<xsl:template match="item" mode="passage">
<xsl:if test="descendant::datafield/entry[preceding-sibling::node()[text()='item_type_code']]/text()='OE'">

1. Found OE item

<xsl:for-each select="preceding-sibling::item[@title !='']">
2. Found a Passage item that relate to OE item.
<xsl:variable name="pass_id" select="@id"/>

<xsl:if test="not(preceding-sibling::item/@id = $pass_id)">
pa_ident= <xsl:value-of select="@id"/><br></br>
  3.Don't print duplicate passage
</xsl:if>

</xsl:for-each>

</xsl:if>

</xsl:template>

</xsl:stylesheet>


I want the Out put as :
pa_ident= 9191
pa_ident= 9993
pa_ident= 9983
pa_ident= 9987
pa_ident= 9160
pa_ident= 9087

but I can’t filtering the duplicated item out (pa_ident= 9993).
Here's what I did:
step1:Found OE item
step2: Found a PA item that relate to OE item.
step3: filter out the duplicated PA item

(I can't get step3 work correctly)
Thanks you in advance.
Fanyin
 
Old November 4th, 2004, 03:18 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

One way I can think of is to use a different search path.
Please correct me if I'm wrong.

So step by step:
Find a matching datafield:
datas/data/item/datafield[entry='OE' and label='item_type_code']

Find data:
datas/data/item/datafield[entry='OE' and label='item_type_code']/../..

Find PA items in the same data as an OE item:
datas/data/item/datafield[entry='OE' and label='item_type_code']/../..item/datafield[entry='PA' and label='item_type_code']/..

so find them all and sort them by id.
<xsl:for-each select="datas/data/item/datafield[entry='OE' and label='item_type_code']/../..item/datafield[entry='PA' and label='item_type_code']/..">
<xsl:sort select="@id">
</xsl:for-each>

should be a lot easier to check if there is a duplicate this way. I hope this helps!:)
 
Old November 4th, 2004, 08:06 PM
Registered User
 
Join Date: Oct 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thank you very much for letting me learn the solution. Fanyin






Similar Threads
Thread Thread Starter Forum Replies Last Post
Filtering XML data aldwinenriquez XSLT 7 August 25th, 2008 03:24 AM
Filtering Data after its been cached Durkee VB.NET 2002/2003 Basics 0 November 13th, 2007 05:57 PM
representing duplicated data in a list box jaredcat Access 1 July 18th, 2006 12:20 PM
Filtering User data donydog Classic ASP Databases 0 February 6th, 2006 09:33 PM
Filtering data by code rodrigoss BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 2 June 23rd, 2004 02:06 PM





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