cy0002 Posted November 6, 2006 Share Posted November 6, 2006 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 More sharing options...
boen_robot Posted November 6, 2006 Share Posted November 6, 2006 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 More sharing options...
cy0002 Posted November 6, 2006 Author Share Posted November 6, 2006 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 More sharing options...
boen_robot Posted November 6, 2006 Share Posted November 6, 2006 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?ThanksThe 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 More sharing options...
cy0002 Posted November 6, 2006 Author Share Posted November 6, 2006 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 More sharing options...
boen_robot Posted November 7, 2006 Share Posted November 7, 2006 <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 More sharing options...
cy0002 Posted November 7, 2006 Author Share Posted November 7, 2006 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now