imbr Posted November 24, 2005 Share Posted November 24, 2005 HiHow can i read data from an xml file like this.<Recipients> <Recipient no="1"custno="12345"> <Recipient no="2"custno="23456"> <Recipient no="3"custno="34567"></recipients>My problem is, that there are two values to select and it doesn't work.How can i get custno?????<xsl:for-each select="Recipients/Recipient"><xsl:value-of select="custno"/> RegardsImbr Link to comment Share on other sites More sharing options...
steve_marjoribanks Posted November 24, 2005 Share Posted November 24, 2005 HiHow can i read data from an xml file like this.<Recipients> <Recipient no="1"custno="12345"> <Recipient no="2"custno="23456"> <Recipient no="3"custno="34567"></recipients>My problem is, that there are two values to select and it doesn't work.How can i get custno?????<xsl:for-each select="Recipients/Recipient"><xsl:value-of select="custno"/> RegardsImbr<{POST_SNAPBACK}> The problem is that you have used empty Recipient tags and no closed them properly. It should be: <Recipient no="1" custno="12345"/> <Recipient no="2" custno="23456"/> <Recipient no="3" custno="34567"/> Link to comment Share on other sites More sharing options...
imbr Posted November 24, 2005 Author Share Posted November 24, 2005 The problem is that you have used empty Recipient tags and no closed them properly. It should be: <Recipient no="1" custno="12345"/> <Recipient no="2" custno="23456"/> <Recipient no="3" custno="34567"/><{POST_SNAPBACK}> You are so right!Unfortunately it still doesn't work.The problem is the number of values within the tag.Normally i would write <Recipient>12345<Recipient/> and i would have no problem reading the data.How can i get hold of custno when the xml-file is created this way:<Recipient no="1" custno="12345"/>Regards imbr Link to comment Share on other sites More sharing options...
bd1e0d0 Posted November 26, 2005 Share Posted November 26, 2005 You wrote: <Recipient>12345<Recipient/>I hope you didn't REALLY type it like that. It's suppsed to be <Recipient>12345</Recipient>, maybe that's another reason for the errors. Link to comment Share on other sites More sharing options...
Skemcin Posted November 26, 2005 Share Posted November 26, 2005 In XML, attributes are not really supposed to be used as data that is intended to be extracted - they really more like side notes. If you are intending to extract the information, especially multiple peices of it, then you should consider reformating the XML.Something like this would work: <parent_node><recipient> <number>1</number> <customer_number>12345<customer_number></recipient><recipient> <number>2</number> <customer_number>23456<customer_number></recipient><recipient> <number>3</number> <customer_number>34567<customer_number></recipient></parent_node> Two other suggestions:a.) use lower case all the time - since XML is case sensitive, take the headache out of one area to troubleshoot - I notice your opening <recipients> tag was proper case but your closing one was not.b.) use singular tense names - it is another way to reduce troubleshooting - plus you are really only speaking about ONE record at a time.Hope this helps.Oh, this won't be much help if you do not have control of the XML feed obviously. Link to comment Share on other sites More sharing options...
steve_marjoribanks Posted November 27, 2005 Share Posted November 27, 2005 You are so right!Unfortunately it still doesn't work.The problem is the number of values within the tag.Normally i would write <Recipient>12345<Recipient/> and i would have no problem reading the data.How can i get hold of custno when the xml-file is created this way:<Recipient no="1" custno="12345"/>Regards imbr<{POST_SNAPBACK}> As said above, you need to make sure all your closing tags are the same as your opening tags, watch for capital letters!Again, closing tags are of the format </name> not <name/>. The reason i put it like <Recipient no="1" custno="12345" /> is that you are using an empty element and so you can use the shorthand of the /> at the end of the element. It is empty because you don't have any data stored in there, only attribute values. As mentioned above, it is generally a better idea to store data in element form as it is more versatile then.If the data has to be stored as attributes then you have to search for the data in the attributes. At the moment you are telling it to look for an element called custno, not an attribute.You need to change it to:<xsl:for-each select="Recipients/Recipient"><xsl:value-of select="@custno"/></xsl:for-each>the @ tells it to look for an attribute name and not an element name. 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