XML Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreXML Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 26th, 2004, 01:20 PM
clemusa clemusa is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 1 clemusa User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
xml with "almost" html inside

Hello,

I have an xml document with an element like this
<ABSTRACT>some text....
Here is the link
<a href="http://website.com">Website</a></ABSTRACT>

I'm using xsl to display it.

<xsl:for-each select="ABSTRACT">
<xsl:value-of select="."/>
</xsl:for-each>


How could i get the html tag working ?

I know that if it was <a href="http://website.com">Website</a> inside the element it would work using xsl:copy-of but i have < > instead and can't do anything about it.

Thanks for your help,
Clement

Reply With Quote
  #2  
Old July 27th, 2004, 04:43 PM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Try this
Code:
<xsl:for-each select="ABSTRACT">
<xsl:value-of select="." disable-output-escaping="yes"/>
</xsl:for-each>

Reply With Quote
  #3  
Old July 27th, 2004, 10:33 PM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
If the only links you have are anchor tags, this should work. It might be able to be adapted to other tags or <a> tags with more than simple hrefs, but I'll leave that to you. There may be a simpler way to do this, but I am unfamiliar with it (if you find one that works, please post!). Also, this could be slow with large xml files. The test sample I used was fairly short.

With this xml (note addition of the <file> tags-there must be only one top-level element):
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<?xml
-stylesheet type="text/xsl" href="almost_html.xsl"?>
<file>
   <ABSTRACT>
      some text....
      Here is the link <a href="http://website.com">Website</a>
   </ABSTRACT>
   <ABSTRACT>
      some text....
      Here is the link <a href="http://website.com">Website</a>
      Here is some more text and another link
      <a href="http://website.com">Website</a>
   </ABSTRACT>
   <ABSTRACT>
      some text....
      Here is the link <a href="http://website.com">Website</a>
   </ABSTRACT>
</file>


Use this xsl (warning long & confusing )
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="html" />

<xsl:template match="/">
   <html>
      <head>
         <title>bleh</title>
      </head>
      <body>
         Here is the xml:
         <hr/>
         <xsl:for-each select="//ABSTRACT">
            <p>Input text is: <xsl:value-of select="."/></p>
            <xsl:call-template name="links">
               <xsl:with-param name="input_text">
                  <xsl:value-of select="."/>
               </xsl:with-param>
            </xsl:call-template>
         </xsl:for-each>
         <hr/>
      </body>
   </html>
</xsl:template>

<xsl:template name="links">
   <xsl:param name="input_text"/>
   
   <xsl:variable name="before_text"
                 select="substring-before($input_text,'<a')" />
   <xsl:variable name="foo"
                 select="substring-after($input_text,'<a')" />
   <xsl:variable name="tag"
                 select="substring-before($foo,'>')" />
   <xsl:variable name="bar"
                 select="substring-after($foo,'>')" />
   <xsl:variable name="linktext" 
                 select="substring-before($bar,'</a>')" />
   <xsl:variable name="next_text"
                 select="substring-after($bar,'</a>')" />
   <xsl:variable name="wobble"
                 select="substring-before($next_text,'<a')" />
   
   <xsl:value-of select="$before_text"/>
   <a>
      <xsl:attribute name="href">
         <xsl:value-of select="$tag" />
      </xsl:attribute>
      <xsl:value-of select="$linktext"/>
   </a>
   <xsl:if test="$wobble">
      <xsl:call-template name="links">
         <xsl:with-param name="input_text">
            <xsl:value-of select="$next_text"/>
         </xsl:with-param>
      </xsl:call-template>      
   </xsl:if>   
</xsl:template>

</xsl:stylesheet>

Reply With Quote
  #4  
Old July 28th, 2004, 11:49 AM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
I'm sorry. I tested again the one I posted and it didn't work. I can't remember in which cases it worked. If I can find it, I will write back.

Reply With Quote
  #5  
Old July 28th, 2004, 02:12 PM
Teflon's Avatar
Teflon Teflon is offline
Teflon The Black
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Location: Woodbridge VA
Posts: 246 Teflon User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 28 m 14 sec
Reputation Power: 5
Send a message via AIM to Teflon
this worked for me, via php5 transform to html, as well as opening up in IE, for some reason it wouldnt work with firefox. . .?

test.xml
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<?xml
-stylesheet type="text/xsl" href="test.xsl"?>
<xml>
    <abstract>
        Here is the link <a href="http://website.com">Website</a>
    </abstract>
</xml>

test.xsl
PHP Code:
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
    <xsl:template match="xml">
            <xsl:value-of select="abstract" disable-output-escaping="yes"/>
    </xsl:template>
</xsl:stylesheet>
__________________
Teflon - The Black <desc>Mark This Up</desc>

Reply With Quote
  #6  
Old July 28th, 2004, 02:18 PM
Malinali Malinali is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2003
Location: Buenos Aires, Argentina
Posts: 74 Malinali User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
ah! The xslutput piece, that's what was missing.

Reply With Quote
  #7  
Old July 29th, 2004, 02:05 AM
NotGoddess's Avatar
NotGoddess NotGoddess is offline
Kung-fu Kitty
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2004
Posts: 350 NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level)NotGoddess User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 4 Days 6 h 9 m 2 sec
Reputation Power: 10
Send a message via AIM to NotGoddess
Thank you for your much cleaner solution-definately the way to go if the poster can. I had tried that but it would not render for me.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > xml with "almost" html inside


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT