Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 28th, 2016, 11:24 AM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Select Different Element Value as Same Position as First Value

Hello.

I have an XML file with the following <PRESCRIBINGPROVIDER> tag that occurs
within each <DETAILLINE>. I need to find the first occurrence of the
<PRESCRIBINGPROVIDER><FULLNAME> along with it's matching <NATIONALPROVIDERID>.

The problem is that for example, the first occurrence of <PRESCRIBINGPROVIDER> may have a value but it's <NATIONALPROVIDERID> may be blank.

The second occurrence may have a value for both tags.

It's OK to pick up the first occurrence of <PRESCRIBINGPROVIDER> but I need to pick up the same position() value for the <NATIONALPROVIDERID>, even if its empty.

The code I'm using picks up the first occurrence of <NATIONALPROVIDERID> but then the first occurrence of <NATIONALPROVIDERID> that is not blank from the second occurrence of <PRESCRIBINGPROVIDER>.

Code:
<xsl:variable name="varPrescriberName">
  <xsl:value-of select="/doc/EOB/DETAIL/DETAILLINE/PRESCRIBINGPROVIDER[FULLNAME!='']/FULLNAME"/>
</xsl:variable>
<xsl:variable name="varPrescriberNPI">
  <xsl:value-of select="/doc/EOB/DETAIL/DETAILLINE/PRESCRIBINGPROVIDER/NPIINFO[NATIONALPROVIDERID!='']/NATIONALPROVIDERID"/>
</xsl:variable>
Here's an example showing two occurrences of <PRESCRIBINGPROVIDER>.
Code:
<PRESCRIBINGPROVIDER>
  <FULLNAME>FULLNAME LINE 1</FULLNAME>
  <NPIINFO>
    <NATIONALPROVIDERID></NATIONALPROVIDERID>
    <QUALIFIER></QUALIFIER>
  </NPIINFO>
</PRESCRIBINGPROVIDER>
<PRESCRIBINGPROVIDER>
  <FULLNAME>FULLNAME LINE 2</FULLNAME>
  <NPIINFO>
    <NATIONALPROVIDERID>NPI LINE 2</NATIONALPROVIDERID>
    <QUALIFIER></QUALIFIER>
  </NPIINFO>
</PRESCRIBINGPROVIDER>
I need to be able to pick up <NATIONALPROVIDERID> from position(1) instead of position(2).

I've played around with the position function but have not been able to achieve what I need.

Any help will be greatly appreciated!
Rita

Last edited by ritagr; June 28th, 2016 at 12:32 PM..
 
Old June 28th, 2016, 12:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I'm sorry, Rita, I don't understand what it is that you are trying to achieve. Please provide specimen input and output and explain how they are related. If you want to know why your code is wrong, then please supply your complete code, not a vague description of it.

The most common mistakes with position() are (a) to assume that it gives you the position of a node among its siblings, rather than its position among the nodes selected for processing, and (b) to use it in a context (e.g. a predicate) that sets a new position.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
The Following User Says Thank You to mhkay For This Useful Post:
ritagr (June 28th, 2016)
 
Old June 28th, 2016, 12:40 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Thanks Michael for your response. In my XML example, I inadvertently had a value in position(1) for <NATIONALPROVIDERID>. I've since updated it to have spaces.

So, position (1) of PRESCRIBINGPROVIDER/FULLNAME is "FULLNAME LINE 1" and position (1) of PRESCRIBINGPROVIDER/NPIINFO/NATIONALPROVIDERID> is blank.

position (2) <FULLNAME> is "FULLNAME LINE 2" and position (2) <NATIONALPROVIDERID> is "NPI LINE 2".

I need to pick up the first <FULLNAME> value that is not blank along with it's associated <NATIONALPROVIDERID>.

In my XML example that would translate to FULLNAME of "FULLNAME LINE 1" and
NATIONALPROVIDERID blank.

Using my code, however, I get FULLNAME value "FULLNAME LINE 1" and NATIONALPROVIDERID value "NPI LINE 2".

Hope this helps!

Thanks, Rita
 
Old June 28th, 2016, 01:59 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default Select Different Element Value as Same Position as First Value

I'm unable to attach files.

This is what I see under my posting rules:
You may post new threads
You may post replies
You may not post attachments
You may edit your posts

I went to edit my profile but could not see where to change the posting attachments.
 
Old June 28th, 2016, 02:01 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I asked you to show your required output, and/or your code. You haven't done either.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old June 28th, 2016, 02:20 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

I'm unable to attache files - I don't have permission to do this. I'm currently "chatting" with Wiley to help me regarding this.

I have the two files ready to attach. They are rather large but I can email them to you if you prefer.
 
Old June 28th, 2016, 04:57 PM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

Wouldn't the following give you what you want?

Code:
/doc/EOB/DETAIL/DETAILLINE/PRESCRIBINGPROVIDER[FULLNAME!='']/NPIINFO/NATIONALPROVIDERID
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
ritagr (June 28th, 2016)
 
Old June 28th, 2016, 05:20 PM
Authorized User
 
Join Date: Apr 2010
Posts: 61
Thanks: 12
Thanked 0 Times in 0 Posts
Default

Thank you so much! That worked perfectly!!
So appreciate your help.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to select value of element RobertvG XSLT 2 September 15th, 2010 03:50 AM
How to get the position of an element nazran Javascript How-To 3 February 2nd, 2010 06:56 AM
Spacing issue with Position element in IE6 socoolbrewster CSS Cascading Style Sheets 5 October 8th, 2007 02:02 PM
XSL select by child element value vivhost XSLT 3 May 21st, 2005 02:58 AM
select wildcard element names groovepapa XSLT 4 September 1st, 2004 08:12 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.