Rickm
03-31-2008, 02:43 PM
I'm struggling to display hyperlinks within sentences using asp, xml and xsl.
Basically, I can create links correctly until I insert blocks of words in xml and
when I want to make a particular word link, I run into trouble.
Here is what I mean:
Sample XML Code:
<reports>
<report>
<valueset>
<value>The 2007 legislature adjourned April 29 and sent
<link url="http://www.dot.iowa.gov/fakeaddress.html" desc="99 House and 123 Senate files"> to the Governor. Copies of all enrolled bills are available. . .
</value>
</report>
</reports>
Sample XSL Code:
<xsl:for-each select="valueset/value">
<xsl:value-of select="."/>
<xsl:apply-templates select="link"/><br/><br/>
</xsl:for-each>
<xsl:template match="valueset/value/link" >
<xsl:if test="string-length(@url)=0" >
<xsl:value-of select="@desc"/>
</xsl:if>
<xsl:if test="string-length(@url)>0" >
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:value-of select="@desc"/>
</a>
</xsl:if>
</xsl:template>
What happens is that the link gets displayed at the beginning of the value or at the end of the value.
I'm not very technical so if there is an easy way to explain how I can make this work I would sure love to read it.
Thanks
Basically, I can create links correctly until I insert blocks of words in xml and
when I want to make a particular word link, I run into trouble.
Here is what I mean:
Sample XML Code:
<reports>
<report>
<valueset>
<value>The 2007 legislature adjourned April 29 and sent
<link url="http://www.dot.iowa.gov/fakeaddress.html" desc="99 House and 123 Senate files"> to the Governor. Copies of all enrolled bills are available. . .
</value>
</report>
</reports>
Sample XSL Code:
<xsl:for-each select="valueset/value">
<xsl:value-of select="."/>
<xsl:apply-templates select="link"/><br/><br/>
</xsl:for-each>
<xsl:template match="valueset/value/link" >
<xsl:if test="string-length(@url)=0" >
<xsl:value-of select="@desc"/>
</xsl:if>
<xsl:if test="string-length(@url)>0" >
<a target="_blank">
<xsl:attribute name="href">
<xsl:value-of select="@url"/>
</xsl:attribute>
<xsl:value-of select="@desc"/>
</a>
</xsl:if>
</xsl:template>
What happens is that the link gets displayed at the beginning of the value or at the end of the value.
I'm not very technical so if there is an easy way to explain how I can make this work I would sure love to read it.
Thanks