Connecting Tech Pros Worldwide Help | Site Map

pulling and using an uri from an rss encode tag

Newbie
 
Join Date: Aug 2008
Posts: 9
#1: Aug 6 '08
I am relatively new to XSL transforms so I apologize if my language or verbage is incorrect.

I am trying to invoke a JS function of a flash player which requires a URI. In order to do this I would like to take the RSS feed, the snippet below, and grab the uri from the <enclosure> tag. You will see that there is a &uri=channels/39174/186941 inside of the url="" i would like to grab this piece and insert it into my XSL <a href= as currently defined by $item_enclosure.

Here is my XML:
Expand|Select|Wrap|Line Numbers
  1. <item>
  2. <title>New Show: Mobile Show 434</title>
  3. <link>http://www.kyte.tv/ch/39174-flocam/186941-mobile-show-434</link>
  4. <guid>http://www.kyte.tv/ch/39174-flocam/186941-mobile-show-434</guid>
  5. <description>&lt;a href='http://www.kyte.tv/ch/39174-flocam/186941-mobile-show-434'&gt;&lt;img src='http://media06.kyte.tv/store/005/06/crr/0808/05/04/694822-37003-08042008077_120_90-tom-1000.jpg?aid=21808&amp;h=c572dfe49ef7e0704a003559429b4605' title='Mobile Show 434' width='120' height='90' alt='Mobile Show 434' border='0'/&gt;&lt;/a&gt;&lt;br&gt;produced by coflo.</description>
  6.  
  7. <pubDate>Tue, 05 Aug 2008 04:10:00 +0000</pubDate>
  8. <media:content url="http://www.kyte.tv/flash.swf?appKey=MarbachViewerEmbedded&amp;uri=channels/39174/186941&amp;layoutMode=default" fileSize="30" type="application/x-shockwave-flash" height="425" width="425" duration="1"/>
  9. <enclosure url="http://www.kyte.tv/flash.swf?appKey=MarbachViewerEmbedded&amp;uri=channels/39174/186941&amp;layoutMode=default" length="30" type="application/x-shockwave-flash"/>
  10. </item>
  11.  
-----------

As you can see in my XSL im able to pull the url and insert it but i have no idea how to extract the uri=channels/39174/186941

Here is my attempt XSL:

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="item">
  2. <xsl:variable name="item_link" select="link"/>
  3. <xsl:variable name="item_enclosure" select="enclosure/@url"/>
  4. <xsl:variable name="item_title" select="description"/>
  5. <xsl:variable name="item_media" select="media"/>
  6. <div class="subHead" style="width:300px;">
  7. <a href="javascript:void(kyteplayer.setURI('{$item_enclosure}'))"><xsl:value-of select="title" disable-output-escaping="yes"/></a></div>
  8. <div style="width:300px;">
  9. <xsl:value-of select="description" disable-output-escaping="yes"/><br/></div>
  10.  
  11. (<xsl:value-of select="pubDate"/>)<br/> <hr/>
  12.  
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#2: Aug 7 '08

re: pulling and using an uri from an rss encode tag


Getting the url:
substring-after(//enclosure/@url/, 'uri=')
This gets everything after uri=
Now the problem is, is there another argument afterwards? If so, we can take everything before the &; if not we simply take the whole substring.
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="afterURI" select="substring-after(//enclosure/@url/, 'uri=')"/>
  2. <xsl:variable name="URIVal">
  3.   <xsl:choose> 
  4.       <xsl:when test="contains($afterURI, '&amp;amp;')">
  5.          <xsl:value-of select="substring-before($afterURI, '&amp;amp;')"/>
  6.       </xsl:when>
  7.       <xsl:otherwise>
  8.         <xsl:value-of select="$afterURI"/>
  9.       </xsl:otherwise>
  10.    </xsl:choose>
  11. </xsl:variable>
  12.  
Then when you want to output this,
Expand|Select|Wrap|Line Numbers
  1. <a href="javascript:void(kyteplayer.setURI('{$URIVal}'))"><xsl:value-of select="title" disable-output-escaping="yes"/></a>
  2.  
Newbie
 
Join Date: Aug 2008
Posts: 9
#3: Aug 7 '08

re: pulling and using an uri from an rss encode tag


I seem to be getting an error: SAXParseException: Unterminated entity reference

it is always pointing to the line that starts with
Expand|Select|Wrap|Line Numbers
  1. <xsl:variable name="afterURI" select="substring-after(//enclosure/@url/, '&uri=')"/>
Newbie
 
Join Date: Aug 2008
Posts: 9
#4: Aug 7 '08

re: pulling and using an uri from an rss encode tag


Ahh!! I got it, took a bit of playing around but thank you so much for your help - here is my final result working!

Expand|Select|Wrap|Line Numbers
  1. <xsl:template match="item">
  2.  
  3.  
  4.  
  5.   <xsl:variable name="item_link" select="link"/>
  6.   <xsl:variable name="item_enclosure" select="enclosure/@url"/>
  7.   <xsl:variable name="item_title" select="description"/>
  8.   <xsl:variable name="item_media" select="media"/> 
  9.  
  10. <xsl:variable name="afterURI">
  11. <xsl:value-of select = "substring-after($item_enclosure, '&amp;uri=')" />
  12. </xsl:variable>
  13.  
  14.  
  15.        <xsl:variable name="URIVal">
  16.         <xsl:choose>
  17.             <xsl:when test="contains($afterURI, '&amp;')">
  18.                <xsl:value-of select="substring-before($afterURI, '&amp;')"/>
  19.             </xsl:when>
  20.             <xsl:otherwise>
  21.               <xsl:value-of select="$afterURI"/>
  22.             </xsl:otherwise>
  23.          </xsl:choose>
  24.       </xsl:variable>
  25.  
  26.   <div class="subHead" style="width:500px;">
  27.     <a href="javascript:void(kyteplayer.setURI('{$URIVal}'))"><xsl:value-of select="title" disable-output-escaping="yes"/></a></div>
  28.     <div style="width:500px;">
  29.  <xsl:value-of select="description" disable-output-escaping="yes"/><br/></div>
  30.  
  31.  (<xsl:value-of select="pubDate"/>)<br/> <hr/>
  32.  </xsl:template>
  33.  
edit: humm the & isnt showing up correctly it should be & a m p
Moderator
 
Join Date: Mar 2006
Posts: 1,103
#5: Aug 8 '08

re: pulling and using an uri from an rss encode tag


yeah, the code tags seem to automatically unescape &amp; as &, sorry forgot about that quirk.
Newbie
 
Join Date: Aug 2008
Posts: 9
#6: Aug 12 '08

re: pulling and using an uri from an rss encode tag


please take a look at the next step of this project on which I am getting hung up on here: http://bytes.com/forum/thread829025.html
Reply