473,408 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,408 software developers and data experts.

Navigating XML

I am trying to create (another) type of report and I have been beating
my head against the wall for several minutes now. Here's the problem:

<CMS27423400_2140CA>
<CMS27423400_2140CA_REF_ProviderIdentificationNumb ers
CMS27423400_2140CA_REF01_ReferenceIdentificationQu alifier="SY"
CMS27423400_2140CA_REF02_ProviderIdentifier="93384 4887"/>
</CMS27423400_2140CA>
<CMS27423400_2140CA>
<CMS27423400_2140CA_REF_ProviderIdentificationNumb ers
CMS27423400_2140CA_REF01_ReferenceIdentificationQu alifier="1G"
CMS27423400_2140CA_REF02_ProviderIdentifier="22334 455"/>
</CMS27423400_2140CA>
<CMS27423400_2140CA>
<CMS27423400_2140CA_REF_ProviderIdentificationNumb ers
CMS27423400_2140CA_REF01_ReferenceIdentificationQu alifier="G2"
CMS27423400_2140CA_REF02_ProviderIdentifier="83126 "/>
</CMS27423400_2140CA>

Note: this is partially through a document, but shouldnt matter. Now, I
can have any of 12 codes where the SY, 1G, and G2 is located, and in
any order. Each record contains these, and I am only attempting to pull
the G2's and store them in a report. I have it set up, but when I run
it I can only pull the G2 if it is the first loop in each record. If I
have three as above, it kicks out. I am trying to figure out how to
step down through them, inside of a heirarchy record, and see if any
are G2's (since sometimes one may not be listed at all). How do I do
this?

Thanks

Aug 3 '06 #1
5 1422
re*****@gmail.com wrote:
step down through them, inside of a heirarchy record, and see if any
are G2's (since sometimes one may not be listed at all). How do I do
this?
Well, you could for-each and test, but the more standard solution would
be to make a single XPath do all the work:
CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe rs[@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier="SY"]

or, to put it on more readable terms,
path/to/some_element[@some_attribute="desired value"]

This returns all the elements which match the path (relative to your
current context) and which have the specified attribute set to the
desired value. See your favorite XPath/XSLT tutorial's section on
"predicate expressions" to learn more about this approach.

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Aug 4 '06 #2
(Note that it'd be easier to give specific advice if you gave us a more
specific illustration of what you're trying to do, or what you did
that's failing. "It isn't working" is not enough detail to diagnose.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Aug 4 '06 #3
I am beginning to think this may be a limitation of the system due to
design, but here it goes. I have the code I posted above, I only need
the G2 code, the rest can be ignored. I am running:

<xsl:choose>
<xsl:when
test="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe r[@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier]
= 'G2'">
<td>
<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe rs/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:otherwise>
Foo
</xsl:otherwise>
</xsl:choose>

It will test the first item of the three, and see see if it equals G2
or not. But I can not get it to test the following two (or up to 21). I
thought of recursion, but I can not think of how to link it in with XML
to run like this, it kept testing the first. I'm thoroughly stumped.
Joe Kesselman wrote:
(Note that it'd be easier to give specific advice if you gave us a more
specific illustration of what you're trying to do, or what you did
that's failing. "It isn't working" is not enough detail to diagnose.)

--
() ASCII Ribbon Campaign | Joe Kesselman
/\ Stamp out HTML e-mail! | System architexture and kinetic poetry
Aug 4 '06 #4
test="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe r[@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier]
= 'G2'"
The ] is misplaced. You're testing whether a node that has this
attribute has the value G2, not whether it has an attribute with the
value G2.

You're also testing whether *any* node which can be found via that path
has the value G2. Is that really what you intended?

<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe rs/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
Value-of returns the value of the first node found that matches the path.
I suspect you meant something more like:
<xsl:for-each
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA">
<xsl:choose>
<xsl:when
test="CMS27423400_2140CA_REF_ProviderIdentificatio nNumber/@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier
= 'G2'">
<td>
<xsl:value-of
select="CMS27423400_2140CA_REF_ProviderIdentificat ionNumbers/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:otherwise>
Foo
</xsl:otherwise>

</xsl:choose>

</xsl:for-each>
.... though that may not be the best way to do what you're actually
trying to do. (The problem with asking how to make a particular solution
work is that people can't offer alternative solutions.)
Aug 4 '06 #5
I'll tell ya, I'm about to go back to formula. I have tried copying
code over from another file that worked fine, once placed in this file
it doesent work. Nothing has worked as it should in this file yet. With
that said, I attempted your latest solution before, and again it only
validates the first, and for some reason now even if it does match as
G2, still proves false...You hinted at a better way to do this, I am
always open to different solutions. I'm a MUD programmer, and if you
ever looked at that code, well, you'd know where I'm comming from hehe.
Joe Kesselman wrote:
test="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe r[@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier]
= 'G2'"

The ] is misplaced. You're testing whether a node that has this
attribute has the value G2, not whether it has an attribute with the
value G2.

You're also testing whether *any* node which can be found via that path
has the value G2. Is that really what you intended?

<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbe rs/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>

Value-of returns the value of the first node found that matches the path.
I suspect you meant something more like:
<xsl:for-each
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA">
<xsl:choose>
<xsl:when
test="CMS27423400_2140CA_REF_ProviderIdentificatio nNumber/@CMS27423400_2140CA_REF01_ReferenceIdentificationQ ualifier
= 'G2'">
<td>
<xsl:value-of
select="CMS27423400_2140CA_REF_ProviderIdentificat ionNumbers/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:otherwise>
Foo
</xsl:otherwise>

</xsl:choose>

</xsl:for-each>
... though that may not be the best way to do what you're actually
trying to do. (The problem with asking how to make a particular solution
work is that people can't offer alternative solutions.)
Aug 4 '06 #6

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

Similar topics

15
by: brundlefly76 | last post by:
As a Perl programmer for many years, this week I decided to stick my toe back into C for a specific project. During which I was tinkering with C++, which I have no production experience in. I...
17
by: Danny J. Lesandrini | last post by:
The following code works with a standard MDB to navigate to a particluar record (with a DAO recordset, of course) but it's giving me problems in an ADP I'm working on. Dim rs As ADODB.Recordset...
2
by: Daveyman | last post by:
Hi, I'm having a problem navigating to/from a subweb using forms authentication. The setup in IIS is as follows: TestSite +----SecureDir +----ReportsSubWeb In VS.Net 2003 this has been...
5
by: Roy Lawson | last post by:
I am having no problems connecting to a DB, creating a DataAdapter, and creating a dataset...and connecting to the data. Using the builtin data objects to do all this. My only problem now is...
1
by: ABC | last post by:
Can I find out when the user is navigating to another page? or What events will be call if the page is change to another page? I want to call clear session variables when user is navigating to...
7
by: hiriumi | last post by:
Hello folks, I have a web application that has basic authentication turned on (IIS). What I would like to accomplish is detect whether user is navigating away from the site or simply going to the...
0
by: tanaji | last post by:
I am writing a web application. In that application I have to need reading data from server during each refresh by using sql query. Refresh time is 10 seconds. BAckend is SQL Server 2000 and frontend...
1
by: JohnMOsborn | last post by:
I am designing an Access database that will use tab controls. Normally, you place different sets of fields on each page of the tab control – like Fields1-3 on Page 1, Fields 4-6 on Page 2, etc. In...
0
by: in10se | last post by:
I have a .NET 2.0 application that uses the WebBrowser control. Because all of my pages are generated dynamically, I am catching the Navigating event, cancelling it, and performing my own operations...
0
by: Anthony Peterson | last post by:
I'm trying to find a solution for my webpage which uses a Datagrid of all editable rows for a spreadsheet sort of style. The tab key works great in navigating across this datagrid, but I would like...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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,...
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...
0
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...

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.