M
mattmozer
I am trying to do a search and replace on an element with a regex. The
problem I am having is on the replace. I am looking for any http(s)
strings and needing to create an href out of it.
This code below works for replace any http(s) with say a text result
such as "fred" or "bob" - for example. You can see what I am
trying to do with it though with the a href. I am using XML Spy on a
windows platform.
<xsl:template match="whatever">
<xsl:copy>
<xsl:value-of select='replace(.,"(https?:\/\/[^\s]*)", "<a
href=$1>$1</a>")'/>
</xsl:copy>
</xsl:template>
The element in this case "whatever" could have multiple http
references and are contained in a text element of arbitrary content and
length. So, with that being said, the below example is not what I'm
looking for as someone has already pointed out. I have tried something
similar to no avail.
<xsl:template match="//addr">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
I need to be able to escape the "<" & ">" characters or change my
approach entirely... I think this would prove to be a valuable tool if
it were to work.
-Matt
problem I am having is on the replace. I am looking for any http(s)
strings and needing to create an href out of it.
This code below works for replace any http(s) with say a text result
such as "fred" or "bob" - for example. You can see what I am
trying to do with it though with the a href. I am using XML Spy on a
windows platform.
<xsl:template match="whatever">
<xsl:copy>
<xsl:value-of select='replace(.,"(https?:\/\/[^\s]*)", "<a
href=$1>$1</a>")'/>
</xsl:copy>
</xsl:template>
The element in this case "whatever" could have multiple http
references and are contained in a text element of arbitrary content and
length. So, with that being said, the below example is not what I'm
looking for as someone has already pointed out. I have tried something
similar to no avail.
<xsl:template match="//addr">
<xsl:element name="a">
<xsl:attribute name="href">
<xsl:value-of select="."/>
</xsl:attribute>
<xsl:value-of select="."/>
</xsl:element>
</xsl:template>
I need to be able to escape the "<" & ">" characters or change my
approach entirely... I think this would prove to be a valuable tool if
it were to work.
-Matt