XSLT med XMLDataSource kontrollen (och GeoNames)

Höll på att testa lite med att koppla en XMLDataSource till en DropDownList och stötte på lite problem. Jag fick följande felmeddelande:

System.Web.UI.WebControls.XmlDataSourceNodeDescriptor innehåller inte någon egenskap med namnet name.

Efter lite sökning på nätet kom jag underfund med att det inte går att ange DataTextField till ett fält-värde i xml-filen. Det ska vara attribut till en tagg för att det ska fungera. Här är ett exempel på den xml fil som jag testade med som för övrigt är genererad av an tjänst på www.geonames.org och visar "first-order administrative division" Sverige. Jag ville få fram alla län men tror inte detta var helt rätt. Resten av parametrarna som man kan skicka med finns på en lista, här.

<geonames>
<totalResultsCount>85543</totalResultsCount>

<geoname>
<name>Stockholm</name>
<lat>59.3294681359869</lat>
<lng>18.0626392364502</lng>
<geonameId>2673730</geonameId>
<countryCode>SE</countryCode>
<countryName>Sweden</countryName>
<fcl>P</fcl>
<fcode>PPLC</fcode>
</geoname>

<geoname>
<name>Gothenburg</name>
<lat>57.7166667</lat>
<lng>11.9666667</lng>
<geonameId>2711537</geonameId>
<countryCode>SE</countryCode>
<countryName>Sweden</countryName>
<fcl>P</fcl>
<fcode>PPLA</fcode>
</geoname>

<geoname>
<name>Uppsala</name>
<lat>59.85</lat>
<lng>17.6333333</lng>
<geonameId>2666199</geonameId>
<countryCode>SE</countryCode>
<countryName>Sweden</countryName>
<fcl>P</fcl>
<fcode>PPLA</fcode>
</geoname>
...
</geonames>

Jag hittade lösningen som jag använder på Raj Kaimal's blogg. För att transformera xml-filen ovan så att name blir ett attribut till geoname kan man använda en XSLT-fil (TransformGeonames.xsl) som ser ut så här.

<?xml version="1.0" encoding="utf-8"?>

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="geonames">
<geonames>
<xsl:apply-templates select="geoname"/>
</geonames>
</xsl:template>
<xsl:template match="geoname">
<geoname>
<xsl:attribute name="name">
<xsl:value-of select="name"/>
</xsl:attribute>
</geoname>
</xsl:template>

</xsl:stylesheet>

Slutligen visar jag den koden som konsumerar web-servicen med XSLT-transformeringen.

<%@ Page Language="C#" AutoEventWireup="true" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>XmlDataSource with XSLT</title>
</head>
<body>
<form id="form1" runat="server">
<asp:dropdownlist ID="Dropdownlist1" DataSourceID="XmlDataSource1" DataTextField="name" runat="server"></asp:dropdownlist>
<asp:XmlDataSource ID="XmlDataSource1" DataFile="http://ws.geonames.org/search?q=sverige&country=SE&fclass=ADM1" TransformFile="TransformGeonames.xsl" XPath="geonames/geoname" runat="server"></asp:XmlDataSource>
</form>
</body>
</html>

Comments

thanks for sharing a good post. http://www.onlinepromotionuae.ae

Data source and also the coding all things are here. And when we have to solve these things then we have many dissertation writings trouble to solve these problems.And hope they are solve their problems by read this data.

If your looking for Online Illinois license plate sticker renewals then you have need to come to the right place.We offer the fastest Illinois license plate sticker renewals in the state. Corn

Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work! Aloe Vera

wow, great, I was wondering how to cure acne naturally. and found your site by google, learned a lot, now i’m a bit clear. I’ve bookmark your site and also add rss. keep us updated. Pineapple

Your blogs further more each else volume is so entertaining further serviceable It appoints me befall retreat encore. I will instantly grab your feed to stay informed of any updates. Bitter Melon

Truly, this article is really one of the very best in the history of articles. I am a antique ’Article’ collector and I sometimes read some new articles if I find them interesting. And I found this one pretty fascinating and it should go into my collection. Very good work! Dates

This was among the best posts and episode from your team it let me learn many new things. Milk

The ziptrack outdoor blinds relax and indulge in your own private retreat,the blind shields simple and safe with this signatureblinds Mission Impossible jacket site. Thanks for great and environment in seconds with simple energy bills.

Most gracious and better objectives on confronted and great struggles always for personal another level,thanks. The great endeared for the important guidance nj limo always,more path and hereafter technical tips by people.

I am imparting it to my different companions as the data is truly exceptionally advantageous. Continue offering your pay someone to write my assignment Fantastic blog entry and exceptionally handy data. I must like the splendid work by splendid scholar. Continue blogging. Good luck.

I am now not sure where you are getting your information, but great topic. I needs to spend uk assignment writing a while finding out more or figuring out more. Thanks for great information I was looking for this info for my project.

Good post!! Your contemplation are outstanding. It appears you have the rich learning about this territory. Give me a chance to uk essay writing tell that you have composed an amazing article. Keep up the great written work.

Appreciated perusing the article above This article is followed by many people to find reviews. every post needed for understanding Buy Ryan Gosling Jacket Online your? website shared new concepts. Then all the people enjoyed with the great values and pages.

Thank you for every other informative site. Where else may just I am getting that type of information written in such a perfect method? I've a undertaking that psychology assignment uk I am simply now running on, and I have been on the glance out for such information.

This is the really great post, I like it. Owen Grady Vest

Wow, Amazing post, I am interested to write on this, I like it, Abbraci

Most charitable and better targets on went up against and incredible battles dependably for individual another level,thanks. The colossal charmed for the vital direction nj limo always,more way and from now on specialized tips by individuals. Buy Cigarette Boxes

Toko Online [URL=https://www.appbrain.com/user/spesialisherbal/]Spesialis Herbal Indonesia[/URL] menyediakan obat herbal bermutu tinggi dengan tujuan memperbaiki performa kesehatan tubuh. Situs Kesehatan Spesialisherbal merupakan pusat obat herbal yang menjual obat herbal bermutu yang terpercaya di Nusantara.

Toko Online Spesialis Herbal Indonesia menyediakan obat herbal bermutu tinggi dengan tujuan memperbaiki performa kesehatan tubuh. Situs Kesehatan Spesialisherbal merupakan pusat obat herbal yang menjual obat herbal bermutu yang terpercaya di Nusantara.

So once you get a card ensure you stay aware of it! (If you do lose it the. ahti

I have this article. I must say this is such an useful article. thanks for sharing such interesting article www.williamjacket.com

For so many months for post natal care. This must be a very stressful time in both of your lives but for the health of...have. Keep that motivation! Good luck with this and I hope.The Walking Dead Rick Grimes Jacket

I just loved your way of presentation. enjoyed reading this .Thanks for sharing and keep writing. It is Obat Herbal Sesak Nafas Pada Anak Paling Ampuh good to read blogs like this. As constantly, we appreciate yourself assurance and accept as true within us.

192.168.1.254

Os doy las gracias por la información! Yo estaba buscando y no podía encontrar. Usted me ayudó!

  1. This article brings a lot of information for us. I agree with the views. This is useful worldwide. https://www.leatherjacketblack.com/product/sheepskin-raf-pilot-ww2-flying-bomber-mens-jacket/"> https://www.leatherjacketblack.com/product/sheepskin-raf-pilot-ww2-flying-bomber-mens-jacket/ "> men jacket. Don’t stop by posting such great articles.
  1. I read this article. This is very informative. It is very glad to see this. https://www.leatherjacketblack.com/product/audrey-marie-anderson-black-jacket-lyla-michaels-arrow/"> https://www.leatherjacketblack.com/product/audrey-marie-anderson-black-jacket-lyla-michaels-arrow/ "> black jacket I really appreciate this.

Jag ville få fram alla län men tror inte detta var helt rätt. Resten av parametrarna som man kan skicka med finns på en lista,

Jag ville få fram alla län men tror inte detta var helt rätt. Resten av parametrarna som man kan skicka med finns på en lista,

granny game horror

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog. Now I saved it to my bookmarks so that I can keep me in touch with you.

I really happy found this website eventually. Really informative and inoperative, Thanks for the post and effort! Please keep sharing more such blog. Now I saved it to my bookmarks so that I can keep me in touch with you.

Pretty Helpful Material, Much Thanks For This Article

This strong article. Hope you will do more good in coming days, thank you for sharing it.

Thanks for this wonderful article and continue sharing more topics like this. router login

Je vous remercie de l'information! Je cherchais et ne pouvait pas trouver. Vous me aidé! 192.168.o.1

Appreciated perusing the article above This article is followed by many people to find reviews. every post needed for understanding your? website shared new concepts. Then all the people enjoyed with the great values and pages.

The information that is provided on your website is amazing and I am always eager to catch hold of the new posts being published on your website, because of this i use to updated,[mr terrific jacket][1] thanks for sharing this wonderful article [1]: https://americasuits.com/men-jackets/fair-play-mr-terrific-jacket"> https://americasuits.com/men-jackets/fair-play-mr-terrific-jacket

Please fill out all the fields.

*
*