Last post Sep 06, 2010 10:23 AM by mehta.rahulit
Member
613 Points
2132 Posts
Sep 03, 2010 05:03 AM|Peter Smith|LINK
I have the XML below, generated by Apache Solr. I want to assign the results (2 <doc>nodes in this case) to a gridview using an XML datasource. <response> - <lst name="responseHeader"> <int name="status">0</int> <int name="QTime">0</int> <lst name="params"> <str name="facet">true</str> <str name="fl"> id,title,city,score,location_rating,introtext,location_rating_total,themes,features,official,services </str> <str name="indent">on</str> <str name="start">0</str> <str name="q">*:*</str> <arr name="facet.field"> <str>province_raw</str> <str>services_raw</str> <str>themes_raw</str> <str>features_raw</str> </arr> <str name="fq">themes:Building</str> <str name="rows">2</str> </lst> </lst> <result name="response" numFound="2" start="0" maxScore="1.0"> <doc> <float name="score">1.0</float> <arr name="features"> <str>Garden</str> <str>Cafe</str> </arr> <str name="id">1</str> <str name="introtext">Boston, its awesome</str> <float name="location_rating">3</float> <int name="location_rating_total">2</int> <arr name="services"> <str>Fotoreport</str> </arr> <arr name="themes"> <str>Building</str> </arr> <str name="title">Boston Mass</str> </doc> - <doc> <float name="score">1.0</float> <arr name="features"> <str>Garden</str> <str>Cafe</str> <str>Dancing</str> </arr> <str name="id">2</str> <str name="introtext">New york,some text</str> <float name="location_rating">0</float> <int name="location_rating_total">0</int> - <arr name="services"> <str>Fotoreport</str> <str>Exclusive rental</str> </arr> <arr name="themes"> <str>Building</str> <str>Oldschool</str> </arr> <str name="title">New York av</str> </doc> </result> I now have this: <asp:GridView ID="gvSearchResults" DataSourceID="XMLDS" runat="server"> <Columns> <asp:TemplateField> <ItemTemplate> <i>Name <%#XPath("title")%></i> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <asp:XmlDataSource ID="XMLDS" runat="server"></asp:XmlDataSource> I've been looking into XSL stylesheets as well, but if someone could help me out getting started it would be much appreciated!
Participant
1213 Points
829 Posts
Sep 03, 2010 06:39 AM|mehta.rahulit|LINK
with a quick glace i can say u have given wrong xPath
u want to show doc elements
so xPath will be
//response/result/doc
let me know if it does not work
Sep 03, 2010 06:45 AM|Peter Smith|LINK
Ok, but how would I then extract the values for these: 1. features (multivalued node) 2. title
Thanks! :)
Sep 03, 2010 08:09 AM|mehta.rahulit|LINK
those are not node those are attribute
make a search to get attribute in xslt
Sep 03, 2010 08:15 AM|Peter Smith|LINK
Im aware those not nodes:) But do you have an example on how I can do it (for my specific scenario)? Thanks again!
Sep 03, 2010 11:00 AM|mehta.rahulit|LINK
the xml and xslt are below.I will try to come with full solution as i get time <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My solution</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th></th>
</tr>
<xsl:for-each select="response/result/doc">
<tr>
<td><xsl:value-of select="arr/@name"/></td>
</xsl:for-each> </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
Sep 03, 2010 11:30 AM|mehta.rahulit|LINK
hi will look into it as i get time
i suggest u to use transformation and bind gridview.
<?xml version="1.0" encoding="iso-8859-1"?> <!-- Edited by XMLSpy® --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/"> <html> <body> <h2></h2> <table border="1"> <tr bgcolor="#9acd32"> <th></th> <th></th> </tr>
<xsl:for-each select="response/result/doc/arr"> <tr> <td> <xsl:if test="@name='features'"> <xsl:value-of select="str"/> </xsl:if>
</td> </tr> </xsl:for-each>
<xsl:for-each select="response/result/doc/str"> <tr> <td> <xsl:if test="@name='title'"> <xsl:value-of select="str"/> </xsl:if> </td> </tr> </xsl:for-each> </table> </body> </html> </xsl:template> </xsl:stylesheet>
Sep 03, 2010 04:02 PM|Peter Smith|LINK
Hi, thanks for the stylesheet! :) But how do I apply this exactly? :$ Thanks again!
Sep 06, 2010 03:03 AM|mehta.rahulit|LINK
http://www.15seconds.com/issue/060608.htm
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
let me know if i can help you
Thanks
Rahul M
Sep 06, 2010 06:54 AM|Peter Smith|LINK
I fixed it in a different way: http://forums.asp.net/t/1598964.aspx Thanks!
Sep 06, 2010 10:23 AM|mehta.rahulit|LINK
Thanks for sharing
Regards,
Member
613 Points
2132 Posts
Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 05:03 AM|Peter Smith|LINK
I have the XML below, generated by Apache Solr.
I want to assign the results (2 <doc>nodes in this case) to a gridview using an XML datasource.
<response>
-
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">0</int>
<lst name="params">
<str name="facet">true</str>
<str name="fl">
id,title,city,score,location_rating,introtext,location_rating_total,themes,features,official,services
</str>
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">*:*</str>
<arr name="facet.field">
<str>province_raw</str>
<str>services_raw</str>
<str>themes_raw</str>
<str>features_raw</str>
</arr>
<str name="fq">themes:Building</str>
<str name="rows">2</str>
</lst>
</lst>
<result name="response" numFound="2" start="0" maxScore="1.0">
<doc>
<float name="score">1.0</float>
<arr name="features">
<str>Garden</str>
<str>Cafe</str>
</arr>
<str name="id">1</str>
<str name="introtext">Boston, its awesome</str>
<float name="location_rating">3</float>
<int name="location_rating_total">2</int>
<arr name="services">
<str>Fotoreport</str>
</arr>
<arr name="themes">
<str>Building</str>
</arr>
<str name="title">Boston Mass</str>
</doc>
-
<doc>
<float name="score">1.0</float>
<arr name="features">
<str>Garden</str>
<str>Cafe</str>
<str>Dancing</str>
</arr>
<str name="id">2</str>
<str name="introtext">New york,some text</str>
<float name="location_rating">0</float>
<int name="location_rating_total">0</int>
-
<arr name="services">
<str>Fotoreport</str>
<str>Exclusive rental</str>
</arr>
<arr name="themes">
<str>Building</str>
<str>Oldschool</str>
</arr>
<str name="title">New York av</str>
</doc>
</result>
I now have this:
<asp:GridView ID="gvSearchResults" DataSourceID="XMLDS" runat="server">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<i>Name <%#XPath("title")%></i>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:XmlDataSource ID="XMLDS" runat="server"></asp:XmlDataSource>
I've been looking into XSL stylesheets as well, but if someone could help me out getting started it would be much appreciated!
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 06:39 AM|mehta.rahulit|LINK
with a quick glace i can say u have given wrong xPath
u want to show doc elements
so xPath will be
//response/result/doc
let me know if it does not work
MCAD
Contributor Award 2011
Member
613 Points
2132 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 06:45 AM|Peter Smith|LINK
Ok, but how would I then extract the values for these:
1. features (multivalued node)
2. title
Thanks! :)
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 08:09 AM|mehta.rahulit|LINK
those are not node those are attribute
make a search to get attribute in xslt
MCAD
Contributor Award 2011
Member
613 Points
2132 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 08:15 AM|Peter Smith|LINK
Im aware those not nodes:) But do you have an example on how I can do it (for my specific scenario)?
Thanks again!
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 11:00 AM|mehta.rahulit|LINK
the xml and xslt are below.I will try to come with full solution as i get time <?xml version="1.0" encoding="ISO-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2>My solution</h2>
<table border="1">
<tr bgcolor="#9acd32">
<th></th>
<th></th>
</tr>
<xsl:for-each select="response/result/doc">
<tr>
<td><xsl:value-of select="arr/@name"/></td>
</tr>
</xsl:for-each> </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
MCAD
Contributor Award 2011
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 11:30 AM|mehta.rahulit|LINK
hi will look into it as i get time
i suggest u to use transformation and bind gridview.
<?xml version="1.0" encoding="iso-8859-1"?>
<!-- Edited by XMLSpy® -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<body>
<h2></h2>
<table border="1">
<tr bgcolor="#9acd32">
<th></th>
<th></th>
</tr>
<xsl:for-each select="response/result/doc/arr">
<tr>
<td>
<xsl:if test="@name='features'">
<xsl:value-of select="str"/>
</xsl:if>
</td>
</tr>
</xsl:for-each>
<xsl:for-each select="response/result/doc/str">
<tr>
<td>
<xsl:if test="@name='title'">
<xsl:value-of select="str"/>
</xsl:if>
</td>
</tr>
</xsl:for-each>
</table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>
MCAD
Contributor Award 2011
Member
613 Points
2132 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 03, 2010 04:02 PM|Peter Smith|LINK
Hi, thanks for the stylesheet! :)
But how do I apply this exactly? :$
Thanks again!
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 06, 2010 03:03 AM|mehta.rahulit|LINK
http://www.15seconds.com/issue/060608.htm
http://www.w3schools.com/xsl/tryxslt.asp?xmlfile=cdcatalog&xsltfile=cdcatalog
let me know if i can help you
Thanks
Rahul M
MCAD
Contributor Award 2011
Member
613 Points
2132 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 06, 2010 06:54 AM|Peter Smith|LINK
I fixed it in a different way: http://forums.asp.net/t/1598964.aspx
Thanks!
Participant
1213 Points
829 Posts
Re: Showing Solr XML results in gridview using xmldatasource
Sep 06, 2010 10:23 AM|mehta.rahulit|LINK
Thanks for sharing
Regards,
Rahul M
MCAD
Contributor Award 2011