473,473 Members | 1,607 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

XPath Queries not working correctly in Schema

i have a file which I get from a vendor. we are using a industry
schema, hr-xml. however, I can't seem to get any XPath expresions to
work when i receive the file. i think i have pinpointed the problem but
now I need a solution.

I have the following template

<xsl:template match="//PersonName">
<xsl:value-of select="normalize-space(FamilyName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(GivenName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(MiddleName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(Affix)"/>
<xsl:text>,</xsl:text>
</xsl:template>

The beginning of my xml file looks like this (this is where the problem
is)

<Enrollment xmlns="http://ns.hr-xml.org/2004-08-02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02
Enrollment.xsd" creationDate="2005-03-31T11:47:26-06:00">

With this I get no data out of my file.

When I change that to

<Enrollment xmlns="creationDate="2005-03-31T11:47:26-06:00">

the above template works and I retrieve the names of everyone in the
file.

Anyone know exactly what the problem is and how I can fix it?

Jul 20 '05 #1
2 1253

This is the most F of faqs,

<xsl:template match="//PersonName">

which matches the same things as

<xsl:template match="PersonName">

a leading // never does anything useful in a match pattern, it only
changes the default priority.

matches PersonName in no-namespace.

similarly

<xsl:value-of select="normalize-space(FamilyName)"/>

selects FamilyName in no-namespace

<Enrollment xmlns="http://ns.hr-xml.org/2004-08-02"

sets the default namespace to http://ns.hr-xml.org/2004-08-02
and I would guess that your PersonName and
FamilyName elements are in that namespace, so these are not matched by
the Xpath expressions above.

add

xmlns:h="http://ns.hr-xml.org/2004-08-02"

to your xsl:stylesheet and then use

<xsl:template match="h:PersonName">
<xsl:value-of select="normalize-space(h:FamilyName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(h:GivenName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(h:MiddleName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(h:Affix)"/>
<xsl:text>,</xsl:text>
</xsl:template>
David
Jul 20 '05 #2


rosemm wrote:
i have a file which I get from a vendor. we are using a industry
schema, hr-xml. however, I can't seem to get any XPath expresions to
work when i receive the file. i think i have pinpointed the problem but
now I need a solution.

I have the following template

<xsl:template match="//PersonName">
<xsl:value-of select="normalize-space(FamilyName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(GivenName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(MiddleName)"/>
<xsl:text>,</xsl:text>
<xsl:value-of select="normalize-space(Affix)"/>
<xsl:text>,</xsl:text>
</xsl:template>

The beginning of my xml file looks like this (this is where the problem
is)

<Enrollment xmlns="http://ns.hr-xml.org/2004-08-02"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ns.hr-xml.org/2004-08-02
Enrollment.xsd" creationDate="2005-03-31T11:47:26-06:00">

With this I get no data out of my file.


The elements are probably in the default namespace so to select them
with an XPath 1.0 expression you need to bind a prefix to that namespace
in the stylesheet e.g.
<xsl:stylesheet
xmlns:hr="http://ns.hr-xml.org/2004-08-02"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
then use that prefix in your XPath expression e.g.
//hr:Person
or
<xsl:value-of select="normalize-space(hr:FamilyName)"/>

See also
<http://www.faqts.com/knowledge_base/view.phtml/aid/34022/fid/1753>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jul 20 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Andrew L | last post by:
Hello all, I am using the oXygen XML editor to create and edit some GML files. I am having some problems though, and wondered if anyone may be able to help. 1. The GML (Geographic Markup...
3
by: Bob | last post by:
Below is some code that use to work. Now it is not and I have yet to figure out why. I want to select the nodes to a nodelist and remove them from the dom. The only thing I can figure is it broke...
3
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...
1
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"...
10
by: Michael C# | last post by:
OK, here's the deal. I have a small XML file that represents a small database table. I load it into a System.XML.XMLDocument. So far so good. I run an XPath query against it to retrieve all the...
3
by: Jason Mobarak | last post by:
Hello -- I'm attempting to get a handle on how to do xpath queries with System.Xml -- so far the biggest hurdle has been how to deal with a default namespace. If I use the test xml: <?xml...
4
by: syed.akhlaq | last post by:
Hi, Does anyone know how can I validate XPath expressions using xsd schema? Thanks
3
by: Arndt Jonasson | last post by:
Let's say we have a schema (maybe expressed in XML Schema, but not necessarily so), that allows this instance document: <top> <txt>This is text</txt> <books> <book>Tarzan</book> <book>Harry...
3
by: musicgold | last post by:
Hi, I am new in XML. But I have done coding in VBA, C, and HTML. I am using VBA to extract data from an xml file. I use Xpathbuilder to generate Xpath queries for my work. However, some Xpath...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
1
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...
0
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...
1
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...
0
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...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.