473,608 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Xpath for unique value

25 New Member
Hi

I have the following xml structure

CONTRACTS
--CONTRACT
---SUPPLIERS
----SUPPLIER
-----SUPPLIERID
-----SUPPLIERNAME

I need to get all unique values for suppliers so I dont get the same supplier more than once. I'm using the following xpath but it's not working:

Xpath = CONTRACTS/CONTRACT/SUPPLIERS/SUPPLIER[not(SUPPLIERID= preceding-sibling::SUPPLI ER/SUPPLIERID)]")

And how can I sort by SUPPLIERNAME?

Many thanks!
Mar 22 '10 #1
4 3265
jkmyoung
2,057 Recognized Expert Top Contributor
Just use preceding instead. Xpath = CONTRACTS/CONTRACT/SUPPLIERS/SUPPLIER[not(SUPPLIERID= preceding::SUPP LIER/SUPPLIERID)]")

Are you using xsl? Perhaps:
<xsl:sort select="SUPPLIE RNAME"/>

This assumes you don't have any other types of SUPPLIER nodes, and if you did you should be using namespaces anyways.
Mar 22 '10 #2
milecimm
25 New Member
This works, thank you very much.

I'm not using xsl. Is there another way?

Thanks again.
Mar 23 '10 #3
jkmyoung
2,057 Recognized Expert Top Contributor
What are you using? ......
Mar 23 '10 #4
milecimm
25 New Member
Hi, I managed to solve the problem with the sorting. This is my code:

My xml is -----> REVISED

Expand|Select|Wrap|Line Numbers
  1. CONTRACTS
  2. --CONTRACT
  3. ---SUPPLIER
  4. ---COMMODITIES
  5. ----COMMODITY
  6. -----COMODDITYNAME
  7.  
  8.  
  9.         Dim xdoc As New XPathDocument("testxml.xml")
  10.         Dim nav As XPathNavigator = xdoc.CreateNavigator()
  11.         Dim expr As XPathExpression
  12.  
  13.  
  14.         expr = nav.Compile("/pf:CONTRACTS/pf:CONTRACT[not(pf:SUPPLIER=preceding::pf:SUPPLIER)]/pf:SUPPLIER")
  15.  
  16.         Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable)
  17.         namespaceManager.AddNamespace("pf", "http://namespace.ac.uk")
  18.         expr.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Text)
  19.         expr.SetContext(namespaceManager)
  20.         Dim nodes As XPathNodeIterator = nav.Select(expr)
  21.  
  22.         If nodes.Count > 0 Then
  23.  
  24.             Dim tr As String = Nothing
  25.  
  26.             myString.AppendLine("<table width='300px' border='0' cellpadding='0' cellspacing='0' border='0' class='datatable1'>")
  27.             myString.AppendLine("<th>Supplier name</th>")
  28.  
  29.             While nodes.MoveNext()
  30.  
  31.                 Dim supplier As XPathNavigator = nodes.Current.SelectSingleNode(".", namespaceManager)
  32.  
  33.                 myString.AppendLine("<tr><td>" & supplier.ToString())
  34.                 myString.AppendLine("</td></tr>")
  35.  
  36.             End While
  37.  
  38.             myString.AppendLine("</table>")
  39.  
  40.             Dim strOutput As String = myString.ToString()
  41.             lblOutput.Text = strOutput
  42.  
  43.  
  44.         Else
  45.  
  46.             lblOutput.Text = "No results for your search"
  47.  
  48.         End If
Mar 24 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

1
6817
by: bdinmstig | last post by:
I refined my attempt a little further, and the following code does seem to work, however it has 2 major problems: 1. Very limited support for XPath features Basic paths are supported for elements, attributes, ".", and "..", plus also the "" predicate format is supported - however, only one predicate per path step is supported, and expr must be a relative path. 2. Poor performance
1
4011
by: Patrick Reilly | last post by:
I am trying to implement a better method than I already have to document database schemas with XML, and use XSLT to both generate database DDL statements (CREATE TABLE, etc) and to transform to HTML for documentation purposes. In particular I want XSLT to transform to HTML so that my XML documents can be "live", doing the transform in the browser. In the new system a very short XML document looks like: <database> <table id="PROVIDER">
14
12158
by: inquirydog | last post by:
Hi- One frusterating thing for me with xsl is that I don't know how to make xslt throw some sort of exception when a value-of path does not exist. For instance, suppose I have the following line in xslt <xsl:value-of select="/blah/q" /> and my xml document does not have a node /blah/q. The output would
3
3037
by: Tjerk Wolterink | last post by:
Hello i have xml code like this: <page:page xmlns:page="namespacefor page"> <page:section> <page:header> <b>Hello</b>There </page:header> <page:content> --- HTML CODE like: <i>Y</i>es i like bla bal <center>bla</center><img> alblalba
3
1714
by: David Elliott | last post by:
I am in the process of creating an application to scrape databases in order to create typed DataSets. One of the last pieces that I need to do is to remap database fields to something more pleasant. In order to do this I have created a static map that will perform the transformation. Below is a sample of an XML Schema that would be returned from the database. What I am looking to do is given a column name, find the node. For...
1
3028
by: Hollywood | last post by:
I have the following XSD created in VS.NET 2003: <?xml version="1.0" encoding="utf-8" ?> <xs:schema id="ReferralSchama" targetNamespace="http://test.org/Referral" elementFormDefault="unqualified" xmlns="http://test.org/Referral" xmlns:mstns="http://test.org/Referral" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata"> <xs:complexType name="ReferralType"> <xs:sequence>
2
5295
by: Jo Goos | last post by:
Hello, I would like to count the unique values of a specific element in an XPath statement. Let's say I have the next XML document ... <CLUB> <MEMBER> <NAME>Fred</NAME> <LOCATION>Canada</LOCATION>
2
2564
by: Bilal | last post by:
Hello, I'm stuck on this problem for quite some time and hope somebody would be able to guide me. Basically, I need to populate a large number of "template" XML files which have all elements/attributes etc. defined but the values in these elements/attributes might be blank or place holders, as two examples below: Example - File type 1
0
2553
by: Torsten Munkelt | last post by:
Hi, I want to write an XML-schema saying that this document <root> <edge type="special"> <target type="one"/> </edge> <edge type="special"> <target type="one"/>
0
8059
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8495
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8145
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6815
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6011
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5475
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4023
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1589
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.