Navigating XML

R

requeth

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_ProviderIdentificationNumbers
CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier="SY"
CMS27423400_2140CA_REF02_ProviderIdentifier="933844887"/>
</CMS27423400_2140CA>
<CMS27423400_2140CA>
<CMS27423400_2140CA_REF_ProviderIdentificationNumbers
CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier="1G"
CMS27423400_2140CA_REF02_ProviderIdentifier="22334455"/>
</CMS27423400_2140CA>
<CMS27423400_2140CA>
<CMS27423400_2140CA_REF_ProviderIdentificationNumbers
CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier="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
 
J

Joe Kesselman

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_ProviderIdentificationNumbers[@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier="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.
 
J

Joe Kesselman

(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.)
 
R

requeth

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_ProviderIdentificationNumber[@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier]
= 'G2'">
<td>
<xsl:value-of
select="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumbers/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:eek:therwise>
Foo
</xsl:eek:therwise>
</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.
 
J

Joe Kesselman

test="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumber[@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier]

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_ProviderIdentificationNumbers/@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_ProviderIdentificationNumber/@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier
= 'G2'">
<td>
<xsl:value-of
select="CMS27423400_2140CA_REF_ProviderIdentificationNumbers/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:eek:therwise>
Foo
</xsl:eek:therwise>

</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.)
 
R

requeth

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 said:
test="CMS27420100_2000C/CMS27420300_2100CA/CMS27423400_2140CA/CMS27423400_2140CA_REF_ProviderIdentificationNumber[@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier]
= '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_ProviderIdentificationNumbers/@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_ProviderIdentificationNumber/@CMS27423400_2140CA_REF01_ReferenceIdentificationQualifier
= 'G2'">
<td>
<xsl:value-of
select="CMS27423400_2140CA_REF_ProviderIdentificationNumbers/@CMS27423400_2140CA_REF02_ProviderIdentifier"/>
</td>
</xsl:when>
<xsl:eek:therwise>
Foo
</xsl:eek:therwise>

</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.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,002
Messages
2,570,261
Members
46,859
Latest member
VallieMcKe

Latest Threads

Top