473,396 Members | 1,933 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

pulling and using an uri from an rss encode tag

9
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 2926
jkmyoung
2,057 Expert 2GB
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
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
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 Expert 2GB
yeah, the code tags seem to automatically unescape &amp; as &, sorry forgot about that quirk.
Aug 8 '08 #5
coflo
9
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
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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...
0
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
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,...

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.