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!
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.
This works, thank you very much.
I'm not using xsl. Is there another way?
Thanks again.
jkmyoung 2,057
Recognized Expert Top Contributor
What are you using? ......
Hi, I managed to solve the problem with the sorting. This is my code:
My xml is -----> REVISED - CONTRACTS
-
--CONTRACT
-
---SUPPLIER
-
---COMMODITIES
-
----COMMODITY
-
-----COMODDITYNAME
-
-
-
Dim xdoc As New XPathDocument("testxml.xml")
-
Dim nav As XPathNavigator = xdoc.CreateNavigator()
-
Dim expr As XPathExpression
-
-
-
expr = nav.Compile("/pf:CONTRACTS/pf:CONTRACT[not(pf:SUPPLIER=preceding::pf:SUPPLIER)]/pf:SUPPLIER")
-
-
Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nav.NameTable)
-
namespaceManager.AddNamespace("pf", "http://namespace.ac.uk")
-
expr.AddSort(".", XmlSortOrder.Ascending, XmlCaseOrder.None, String.Empty, XmlDataType.Text)
-
expr.SetContext(namespaceManager)
-
Dim nodes As XPathNodeIterator = nav.Select(expr)
-
-
If nodes.Count > 0 Then
-
-
Dim tr As String = Nothing
-
-
myString.AppendLine("<table width='300px' border='0' cellpadding='0' cellspacing='0' border='0' class='datatable1'>")
-
myString.AppendLine("<th>Supplier name</th>")
-
-
While nodes.MoveNext()
-
-
Dim supplier As XPathNavigator = nodes.Current.SelectSingleNode(".", namespaceManager)
-
-
myString.AppendLine("<tr><td>" & supplier.ToString())
-
myString.AppendLine("</td></tr>")
-
-
End While
-
-
myString.AppendLine("</table>")
-
-
Dim strOutput As String = myString.ToString()
-
lblOutput.Text = strOutput
-
-
-
Else
-
-
lblOutput.Text = "No results for your search"
-
-
End If
Sign in to post your reply or Sign up for a free account.
Similar topics |
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
|
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">
|
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
|
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
|
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...
| |
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>
|
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>
|
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
|
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"/>
|
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...
|
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...
| |
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,...
|
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...
|
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...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |