Jump to content

[resolved] get text without the <p> </p>


Recommended Posts

when using <xsl:value-of select="audio-caption"/>how do i get the text without the <p> </p>adding /p did not work : <xsl:value-of select="audio-caption/p"/>example of similar full xml file : http://staff.tumblr.com/api/readpart of my xml:

<?xml version="1.0" encoding="UTF-8"?>......<post><audio-caption><p>Test audio post of a ringtone.</p></audio-caption>

part of my xsl:

<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <h2>Blog</h2>	<table> 	  <xsl:for-each select="tumblr/posts/post">	  <tr>		<td>		  <xsl:choose>			<xsl:when test="@type='audio'">			 <xsl:element name="a"><xsl:attribute name="href"><xsl:value-of select="@url"/>			 </xsl:attribute>			   <xsl:value-of select="audio-caption"/>			 </xsl:element>

Edited by Remko van Dokkum
Link to post
Share on other sites

Frankly xsl: value-of should never give you markup, unless it is contained in the node in escaped form (e.g.

<audio-caption><![CDATA[<p>Test audio post of a ringtone.</p>]]></audio-caption>

).So I am currently not sure which problem you face, unless the input is different from what you posted. Please clarify. You might also want to mention which XSLT version (1.0 or 2.0) you use, that helps anyone trying to answer your posts to show you the right approach.

Link to post
Share on other sites
Frankly xsl: value-of should never give you markup, unless it is contained in the node in escaped form (e.g.
<audio-caption><![CDATA[<p>Test audio post of a ringtone.</p>]]></audio-caption>

).So I am currently not sure which problem you face, unless the input is different from what you posted. Please clarify. You might also want to mention which XSLT version (1.0 or 2.0) you use, that helps anyone trying to answer your posts to show you the right approach.

thanks for the info.i added the required info to original post.there is nothing that can be done about the xml data. thats how tumblr generates it.
Link to post
Share on other sites
thanks for the info.i added the required info to original post.there is nothing that can be done about the xml data. thats how tumblr generates it.
if i change the versions of xml and xsl to 2.0 then i can use the replace function to delete the <p> an </p>fn:replace(string,pattern,replace) - http://www.w3schools.com/Xpath/xpath_functions.aspwill the latest browsers on mac and windows support xml xsl v2?
Link to post
Share on other sites
if i change the versions of xml and xsl to 2.0 then i can use the replace function to delete the <p> an </p>fn:replace(string,pattern,replace) - http://www.w3schools.com/Xpath/xpath_functions.aspwill the latest browsers on mac and windows support xml xsl v2?
how do i use the replace function to delete <p> and </p> at the end of the variable $long_audio_caption?part of my xsl code:
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"> <h2>Blog</h2>	<table> 	  <xsl:for-each select="tumblr/posts/post">	  <tr>		<td>		  <xsl:choose>			<xsl:when test="@type='audio'">			  <xsl:text>audio node</xsl:text>			  <xsl:variable name="long_audio_caption">			  <xsl:value-of select="audio-caption"/>			  </xsl:variable>			  <xsl:copy-of select="$long_audio_caption" />

for now i use this workaround : http://geekswithblogs.net/Erik/archive/200.../01/120915.aspx

Edited by Remko van Dokkum
Link to post
Share on other sites

So your elements do not contain "p" elements but rather text nodes with escaped HTML markup. In that case if you don't want to output the escaped markup you have to remove it with text processing, in XSLT 1.0 you indeed need to use named templates, with XSLT 2.0 you can use replace.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...