Jump to content

xsl:for-each


cy0002

Recommended Posts

Hi, I am new to xsl and have a question about xsl:for-each. I am trying to use "xsl:for-each" to loop through this output (BOLD) to extract "eligBenefitPlanDescription". (There is only 1 output in this example) I look at the example and use something like this:<xsl:for-each select="eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation"><xsl:value-of select="eligBenefitPlanDescription"/></xsl:for-each>However, it does not work. I was wondering what have I done wrong? Please help!<eligVerification2Response><eligVerification2Result><eligVerification txnElapsedTime="0.44" responseStatus="A"><eligRequest transactionId="WERS"clientSecurityKey="ABCD"loc_info="true">><eligInfoReceiver providerNumber="11111111"receiverIdCodeQualifier="SV"/><eligSubscriber subscriberId="0010112345" lastName="MAC" firstName="JOHN"subscriberDateOfBirth="01/01/1950"subscriberIdCodeQualifier="MA"middleName="B"subscriberGender="M"subscriberSSN="123456789"subscriberLocationQualifier="CY"subscriberLocationCode="74"><eligSubscriberDate fromDateOfService="01012005"toDateOfService="01012005"/><eligSubscriberTrn verificationNumber="0000001A" /><eligResponse eligType="Medicaid" messageText="PARTIAL" ><eligInformation insuranceTypeCode="MC" serviceTypeCode="01"eligIndicator="L"eligBenefitPlanDescription="NW ABC"coverageLevelCode= "IND"/><eligDates dateQualifier="307" fromEligDate="12/12/2005"toEligDate="12/12/2005"/><subscriberBenefitRelatedEntityInfo entityIdCode="1P" contactNumber="1234567890" managedCarePlanName="ABC (ABCDEFG)" managedCareRegionCode="ABC03"/></eligResponse> </eligSubscriber></eligRequest></eligVerification></eligVerification2Result></eligVerification2Response>

Link to comment
Share on other sites

Have you checked your XML for well formdness? It seems there's an error here:

<eligRequest transactionId="WERS"clientSecurityKey="ABCD"loc_info="true">>

There must be only one ">". And who knows if you have other errors.Also, is the template the for-each is used in with a match="/"? If not, you'll need an alternative XPath expression to access the value. What exactly depends on the actual match.

Link to comment
Share on other sites

I think the output is fine, I run this script and it's working correctly.<xsl:value-of select="eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation/@eligBenefitPlanDescription"/>I just wonder if I can't use <xsl:for-each> to do the job, what other ways can I use?Thanks

Link to comment
Share on other sites

I think the output is fine, I run this script and it's working correctly.<xsl:value-of select="eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation/@eligBenefitPlanDescription"/>I just wonder if I can't use <xsl:for-each> to do the job, what other ways can I use?Thanks
The XML file is called "input" by the way. For the XSLT at least. "Output" is what you get after the transformation :) .In the worst case, use absolute paths. With a slash at the beginning:
<xsl:for-each select="/eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation"><xsl:value-of select="@eligBenefitPlanDescription"/></xsl:for-each>

good thing you just saw eligBenefitPlanDescription is actually an attribute and as such needs the @ :) .

Link to comment
Share on other sites

Thanks for your response!! However, I just tried this below, but it's not working. Thanks<xsl:for-each select="/eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation"><xsl:value-of select="@eligBenefitPlanDescription"/></xsl:for-each>

Link to comment
Share on other sites

<xsl:for-each select="/eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation"><xsl:value-of select="@eligBenefitPlanDescription"/></xsl:for-each>

This should be "working" if by "working" you mean show "NW ABC".If it doesn't, fix the error in the XML I mentioned above, and try again. Believe me, this extra ">" is NOT fine.

Link to comment
Share on other sites

It is working when I take the "/" out from eligVerification2Response (see below)I really appreciate your help!!!!!! Thanks and have a good day!<xsl:for-each select="eligVerification2Response/eligVerification2Result/eligVerification/eligRequest/eligSubscriber/eligResponse/eligInformation"><xsl:value-of select="@eligBenefitPlanDescription"/></xsl:for-each>

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...