Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Transformation for CDATA in XML View modes: 
User avatar
Member
Member
ezelewsky-lbpc - 2/3/2014 11:41:19 AM
   
Transformation for CDATA in XML
We have a simple XML file that has a single element with several attributes and CDATA inside. The portal template uses the XML Data Source and Basic Repeater webparts. The transformation works fine on the attributes with a simple Eval("attribute"), but numerous approaches haven't been able to pull the CDATA.

We're running v7.0.29, using the portal engine.

The XML file right now is in the CMS for development purposes, but ultimately we may want to point the XML Data Source webpart to an external file. The WHERE statement in the Data Source webpart is set to return only type='4030' — there are about 10 types in the XML file. The XML is structured like so:

<posts>
<post type="4030" file="posts1207.xml" date="12/7/2012" title="WILLIAM RHOLL">
<![CDATA[<p style="text-align:left;">#123456</p><p style="text-align:center;"><strong>WILLIAM RHOLL</strong></p>
<p style="text-align:center;"><strong>Posting</strong></p>
<p style="text-align:justify;text-justify:auto;">The Great, Magnificent Lebowski. No. 144677.</p>
<p style="text-align:justify;text-justify:auto;">Lebowski ipsum well sir, it's this rug I have, really tied the room together. Dolor sit amet, consectetur adipiscing elit praesent ac magna justo pellentesque ac lectus. When he moved down to Venice he had to go door-to-door to tell everyone he's a pederast.</p>
<p style="text-align:justify;text-justify:auto;">This is not the issue! Suscipit malesuada non, ultrices non urna sed orci ipsum. Look at that freaking phony, Dude! Pretending to be a millionaire! Placerat id condimentum rutrum, rhoncus ac. Would it be possible for me to get my twenty grand in cash?</p>
<p style="text-align:left;">1234567</p>
<p style="text-align:left;">Dec 7, 2012</p>]]>
</post>
<post type="4030" file="posts1207.xml" date="12/7/2012" title="JOHN GOODMAN">
<![CDATA[<p style="text-align:left;">#123456</p><p style="text-align:center;"><strong>JOHN GOODMAN</strong></p>
<p style="text-align:center;"><strong>Posting</strong></p>
<p style="text-align:justify;text-justify:auto;">Vee belief in nossing, Lebowski. No. 1236677.</p>
<p style="text-align:justify;text-justify:auto;">I gotta check this with my accountant of course. Lorem aliquam placerat posuere neque.</p>
<p style="text-align:justify;text-justify:auto;">Nice marmot. Ut ultricies ipsum morbi eget risus nulla nullam vel nisi enim, vel auctor. All right, Plan B. You might want to watch out the front window there, Larry. Ante morbi id urna vel felis lacinia placerat vestibulum. They call Los Angeles the City of Angels.</p>
<p style="text-align:left;">7654321</p>
<p style="text-align:left;">Dec 7, 2012</p>]]>
</post>
</posts>

This transformation works OK in the Basic Repeater for the attributes:
<div><%# Eval("date") %> — <%# Eval("type") %> — <%# Eval("title") %></div>

However, <%# EvalCDATA("post") %> doesn't return the CDATA. We need a transformation to return the text and render the HTML in the CDATA container.

Any suggestions for the transformation? Also, any suggestions on webparts for searching the XML and returning a results list with links to each <post> in the result set and then displaying a single <post>?

User avatar
Member
Member
kentico_davidb2 - 2/8/2014 12:42:36 AM
   
RE:Transformation for CDATA in XML
Please try the following:
<div><%# Eval("date") %> — <%# Eval("type") %> — <%# Eval("title")  %><%# Eval("post_Text") %></div>

The pattern is NodeName_Text, so if it was a Customer instead of a post, it would be Customer_Text.

Not sure what you mean by the second question though. If you want to display only one post at a time, use a pager or hide everything, but the link and show it by javascript on click. If you are looking for something else, please describe it in more details.


User avatar
Member
Member
ezelewsky-lbpc - 2/10/2014 1:42:47 PM
   
RE:Transformation for CDATA in XML
Thanks, David! The Eval("NodeName_Text") works great.

As for my second question, I've been looking at building a custom filter that would allow searching the text of the CDATA or the title and selecting the type attribute with a drop-down.

If the SetFilter() method of the example code sets the WHERE condition in the XML Data Source webpart, then this approach probably should work if it returns what I've seen in experimenting with different WHERE clauses.

As far as displaying each result, it looks like the Basic Repeater webpart settings for transformation and selected item transformation might take care of it.

In a nutshell, a visitor would go to a page with a search box and drop down (or two) and enter the query, which would be tied to the custom filter. Each item in the results list would show two or three attributes (date, type, title), and each result item would be a LinkButton that would return the CDATA when clicked.

That said, can the Basic Repeater transformation settings handle both the result items and the detail view, with a base transformation and selected item transformation? If so, is it possible to run the second transformation only if the user clicks through an item in the results?

If not, then does a hierarchical transformation make sense? Doing this in javascript would be straightforward with a hidden div, but we don't want to transmit all the data right away in the initial search results.

Thanks again!

User avatar
Member
Member
kentico_davidb2 - 2/11/2014 3:13:48 AM
   
RE:Transformation for CDATA in XML
I think I understand more now, however, I am not sure if this approach will bring you the results you expect.

The XMLDataSource webpart simply downloads the XML from the URL you specify and converts it whole to a DataSet on the server. It uses the WHERE condition and so on to return a subset of the results. It does this every single time.

If there is a pager or filter, it will limit the results further.

Then if you are using a repeater, it will just take the data and apply transformation to them. This is what get's sent to the client browser.

Therefore, if you want to show something using a click method, the easiest option is javascript. Everything is sent once (only results limited by WHERE condition/pager/...) and client browser will simply sow extra data.

However, if you want to use another approach, you could, on the click do a redirect back to the page and include another extra querystring parameter, which would be the DataItemIndex of the clicked item. Then in the transformation, which is being processed on the server, you can check the querystring for DataItemIndex and for such item only, render the extra information.

Now it really depends on your scenario. The javascript will be much faster if you have relatively low number of results displayed, extra information are about a paragraph long and you expect users to click frequently to expand them.

The other method might be faster if you are going to have large number of results and users will rarely click to expand extra information.

Dave

User avatar
Member
Member
ezelewsky-lbpc - 2/11/2014 12:56:28 PM
   
RE:Transformation for CDATA in XML
Thanks for the thorough explanation. The page that uses the XML doesn't generate many secondary clicks, and we'd rather not send all the data after the initial request because the result set potentially could be in the hundreds or even thousands.

That said, the UniPager may be enough of a throttle for our purposes. That way, if users see a huge number of results, they can refine the search parameter. Or they can wade through each results page with, say, five or 10 items per page.

Which leads me to another question: if the UniPager is set to postback (as opposed to querystring), does that have the effect of presenting any and all results at a single URL? For example, www.thesite.com/posts.aspx -- instead of www.thesite.com/posts.aspx?page=2 or ../posts.aspx?page=37

This seems to be the behavior of the pager...

User avatar
Member
Member
kentico_davidb2 - 2/27/2014 2:26:42 AM
   
RE:Transformation for CDATA in XML
Well, in case you select the Postback option, any querystring is irrelevant. The same URL is then being used for all possible values.