|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 ? |
|
#2
|
||||
|
||||
|
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> |
|
#3
|
|||
|
|||
|
yes there could be any amount of link elements
|
|
#4
|
||||
|
||||
|
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. |
|
#5
|
|||
|
|||
|
Thanks alot it works fine.
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > Nesting text and xml |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|