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 February 4th, 2004, 12:40 PM
hellbrand hellbrand is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 14 hellbrand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 38 sec
Reputation Power: 0
Nesting text and xml

I have the following problem.
Code:
<tagwall>
<tag>
	<id>1</id>
	<text>some text <link><url>http://foo.bar</url><title>Foo</title></link> more text</text>
	<username>Hellbrand</username>
	<date>2004-01-27 19:09:18</date>
</tag>
</tagwall>


I want to parse the <link> as a html link.
The parsing it selv is no problem i use xsl for this.
Code:
<xsl:template match="link">
	<xsl:text disable-output-escaping="yes"><a href="</xsl:text>
	<xsl:value-of select="url"/>
	<xsl:text disable-output-escaping="yes">"></xsl:text>
	<xsl:value-of select="name"/>
	<xsl:text disable-output-escaping="yes"></a></xsl:text>
</xsl:template>


But how do i keep the link between sometext and more text ? or is there some other way to present the data so i could avoid the problem ?

Reply With Quote
  #2  
Old February 4th, 2004, 01:35 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
Do you plan to have multiple link elements in a text element?

Code:
<?xml version="1.0" encoding="UTF-8"?>
<tagwall>
	<tag>
		<id>1</id>
		<text>
			some text
			<link><url>http://foo.bar</url><title>Foo</title></link>
			more text
			<link><url>http://foo.bar</url><title>Foo</title></link>
			even some more text			
		</text>
		<username>Hellbrand</username>
		<date>2004-01-27 19:09:18</date>
	</tag>
</tagwall>

Reply With Quote
  #3  
Old February 4th, 2004, 01:37 PM
hellbrand hellbrand is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 14 hellbrand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 38 sec
Reputation Power: 0
yes there could be any amount of link elements

Reply With Quote
  #4  
Old February 4th, 2004, 01:42 PM
MattSidesinger's Avatar
MattSidesinger MattSidesinger is offline
Java PHP Oracle Developer
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2004
Location: C-Bus OH-IO
Posts: 204 MattSidesinger User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 15 m 26 sec
Reputation Power: 5
Send a message via AIM to MattSidesinger
This seemed to work for me. I learned something on this one. I'll let you know if I improve upon it any.

Code:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">

	<xsl:template match="/">
		<xsl:apply-templates select="/tagwall/tag/text"/>
	</xsl:template>
	
	<xsl:template match="text">
		<xsl:for-each select="text()|link">
			<xsl:apply-templates select="."/>
		</xsl:for-each>
	</xsl:template>
	
	<xsl:template match="text()">
		<xsl:value-of select="."/>
	</xsl:template>
	
	<xsl:template match="link">
		<xsl:text disable-output-escaping="yes"><a href="</xsl:text>
		<xsl:value-of select="url"/>
		<xsl:text disable-output-escaping="yes">"></xsl:text>
		<xsl:value-of select="title"/>
		<xsl:text disable-output-escaping="yes"></a></xsl:text>
	</xsl:template>
	
</xsl:stylesheet>

Last edited by MattSidesinger : February 4th, 2004 at 01:44 PM.

Reply With Quote
  #5  
Old February 4th, 2004, 01:46 PM
hellbrand hellbrand is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2004
Posts: 14 hellbrand User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 44 m 38 sec
Reputation Power: 0
Thanks alot it works fine.

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreXML Programming > Nesting text and xml


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 5 hosted by Hostway
Stay green...Green IT