|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
XSL: In-Line Links
I am having trouble finding a way to transform links from XML data into HTML links - and have them appear at the appropriate place in the text.
Consider the following XML data source. <p>This webpage can be found <link url=“http:www.somewhere.com”>here</link> on the web.</p> Now, I have had no trouble grabbing the text of the paragraph for HTML using this XSL: <xsl:for-each select="//p"> <p><xsl:value-of select="."/></p> </xsl:for-each> But, unfortunately that only prints the text and does not create a link. (i.e. HTML result is <p>This webpage can be found here on the web.</p>) I can transform the link data to an HTML link using this XSL: <xsl:for-each select="//link"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="//link/@url" /> </xsl:attribute> <xsl:attribute name="target">blank</xsl:attribute> <xsl:value-of select="//link" /> </xsl:element> </xsl:for-each> But, unfortunately that only prints the link and not the surrounding paragraph. (i.e. HTML result is <a href=“http://www.somewhere.com” target=“blank”>here</a>) My problem is that I would like to transform the link and print the paragraph with the link in it. i.e. I would like for the HTML to be: <p> This webpage can be found <a href=“http:www.somewhere.com” target=”blank>here</a> on the web</p> Can anyone help me with this? |
|
#2
|
||||
|
||||
|
Hope you have this figured out already... If not here's simple solution for you:
Code:
<?xml version="1.0" encoding="iso-8859-1" ?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.1"> <xsl:template match="p"> <html> <body> <p> <xsl:value-of select="substring-before(//p,'here')"/> <xsl:for-each select="//link"> <xsl:element name="a"> <xsl:attribute name="href"> <xsl:value-of select="//link/@url" /> </xsl:attribute> <xsl:attribute name="target">blank</xsl:attribute> <xsl:value-of select="//link" /> </xsl:element> </xsl:for-each> <xsl:value-of select="substring-after(//p,'here')"/> </p> </body> </html> </xsl:template> </xsl:stylesheet> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > XML Programming > XSL: In-Line Links |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|