473,498 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

pulling and using an uri from an rss encode tag

9 New Member
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.  
Aug 5 '08 #1
5 2930
jkmyoung
2,057 Recognized Expert Top Contributor
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.  
Aug 7 '08 #2
coflo
9 New Member
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=')"/>
Aug 7 '08 #3
coflo
9 New Member
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
Aug 7 '08 #4
jkmyoung
2,057 Recognized Expert Top Contributor
yeah, the code tags seem to automatically unescape &amp; as &, sorry forgot about that quirk.
Aug 8 '08 #5
coflo
9 New Member
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
Aug 11 '08 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
4875
by: Newbie | last post by:
How would I modify this form to encode *all* the characters in the 'source' textarea to the '%xx' format & place result code into the 'output' textarea? (cross browser compatable) Any help is...
3
2645
by: Peter | last post by:
Hi, I try to make up a javascript string which contains numeric numbers in any positions. For example, I want to make a string: secretcode, where secretcode.charAt(0)==(-21),...
0
3907
by: Lokkju | last post by:
I am pretty much lost here - I am trying to create a managed c++ wrapper for this dll, so that I can use it from c#/vb.net, however, it does not conform to any standard style of coding I have seen....
4
7546
by: Darrel | last post by:
How does HTML.encode work? I'm trying to save text in a hidden form field into a SQL DB. The tedt is HTML (from a WYSIWYG editor...X-standard). One problem I have is that stray apostrophe's in...
11
3099
by: youngster94 | last post by:
Hey all, I've written a VB.Net app that creates picture badges complete with barcodes. The problem is that the barcode quality is not good enough to be read by scanners. I'm using the...
2
10255
by: aurora | last post by:
I have some unicode string with some characters encode using python notation like '\n' for LF. I need to convert that to the actual LF character. There is a 'unicode_escape' codec that seems to...
6
2317
by: 7stud | last post by:
s1 = "hello" s2 = s1.encode("utf-8") s1 = "an accented 'e': \xc3\xa9" s2 = s1.encode("utf-8") The last line produces the error: --- Traceback (most recent call last):
3
1479
by: tech | last post by:
Hi, i have the following design issue. In our app we use different codecs to encode/decode packets of data I have defined a base codec class as follows class CCodec { public: CCodec() {};...
1
5753
by: anonymous | last post by:
1 Objective to write little programs to help me learn German. See code after numbered comments. //Thanks in advance for any direction or suggestions. tk 2 Want keyboard answer input, for...
1
3845
by: Mudcat | last post by:
In short what I'm trying to do is read a document using an xml parser and then upload that data back into a database. I've got the code more or less completed using xml.etree.ElementTree for the...
0
7005
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7168
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7210
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6891
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7381
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5465
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4916
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
1424
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
659
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.