This project is read-only.

little help to reformat Posterous output

Sep 16, 2010 at 2:51 AM

Hi folks... Just wondering if anyone could help me reformat the following output. I just want to output a simple blog-type format for each "post".

Thanks for any help.

Here's an example source:

<rsp stat="ok"> 
  <title>Den 10 Service Project</title> 
    <![CDATA[>>>><p><img src="" width="240" height="320"/> 
  <date>Tue, 14 Sep 2010 13:01:12 -0700</date> 

Sep 16, 2010 at 1:30 PM


This is simple to do and I can make a working sample for you if you provide a URL that returns XML.

If to put your sample into an xsl:variable you can use the following code to output a list of records

<xsl:variable name="rsp">
  <!-- Your XML goes here  -->
<xsl:for-each select="mdo:node-set($rsp)//post">
  {{title}} - {{mdo:fmt-date(date, 'dd.MM.yyyy HH:mm')}}
  <img src="{media/thumb/url}" style="float:left;margin-right:5px;" />
  <div style="clear:both;"/>

Here I used a title, date and thumbnail. If you need to analyse body tag I'd like you to provide more meaningfull sample. To simply output body as HTML you can use

inside xsl:for-each. ( "{h{" disables HTML encoding. )






Sep 16, 2010 at 2:05 PM
Edited Sep 16, 2010 at 2:08 PM

Thanks Findy!

Ok... I tried that with the URL and I think I am good to go!

Sep 16, 2010 at 2:53 PM

Is it possible to parse html items within a CDATA tag? When I add the {{body}} to the output, the html is output as plain text. I would like to pull out the <div class="downlloadIcon">...</div>
content and place below the <p>...</p> content.

The actual URL is:

       <div class='downloadFlyout'>
       <div class="downloadIcon"><a href=''>
<img src='' style='border: none;'/></a></div> <div class="downloadlinkInstructions">Download now or <a href='' style='color: #bc7134;'>preview on posterous</a></div> <b><a href=''>POPCORN FUNDRAISER.pdf</a></b> <span class="downloadSize">(157 KB)</span> <br class="clearboth"/></div> <p>Attached to this post is the popcorn flyer.<p /></p>

Sep 16, 2010 at 4:26 PM


you can try disabling output-escaping, that is: {h{body}} or 

<xsl:value-of select="body" disable-output-escaping="yes" />


Sep 16, 2010 at 6:25 PM


This is a short sample. You can find it live here: Here you can see how you can parse body and analyse it using XPath.

<style type="text/css">
  .downloadIcon { float:left; }

<!-- download feed and put it in cache for 600 seconds -->
<xsl:variable name="rsp" select="mdo:nodeset('', 600)"/>

<!-- iterate posts -->
<xsl:for-each select="$rsp//post">

  <!-- turn body in XML format: <root> the body </root> -->
  <xsl:variable name="body" select="mdo:node-set(concat('&lt;root&gt;', body, '&lt;/root&gt;'))"/>

  <!-- print date ena title -->
  <div style="padding-bottom:3px;">
    <b>{{mdo:fmt-date(date, 'dd.MM.yyyy HH:mm')}}</b>. {{title}}

  <!-- print image if it is in post -->
  <xsl:if test="media/thumb/url">
    <img src="{media/thumb/url}" style="margin-left:5px;"/>

  <!-- if body contain a downloadable document - print body -->
  <xsl:if test="$body//div[@class='downloadIcon']">

  <div style="clear:both;" />