"David Walker" <da***@cs.cf.ac.uk> wrote in message news:<ca**********@news.swman.net.uk>...
Hi,
I have an XML file created by a third party in which an element with a
simple content model has a text value consisting of 2 parts separated by a
colon, like this
<link>machine:port</link>
Is XSLT capable of parsing the value of a <link> element, to separately
extract the portions before and after the colon?
Regards
David Walker
David,
I suppose there are many ways of achieving that. Here is just one example:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:apply-templates select="link"/>
</xsl:template>
<xsl:template match="link">
<xsl:variable name="machine" select="substring-before( . , ':' ) "/>
<xsl:variable name="port" select="substring-after( . , ':' ) "/>
<xsl:element name="link">
<xsl:element name="machine">
<xsl:value-of select="$machine"/>
</xsl:element>
<xsl:element name="port">
<xsl:value-of select="$port"/>
</xsl:element>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
This will transform Your example
<?xml version="1.0" encoding="UTF-8"?>
<link>machine:port</link>
To the following:
<?xml version="1.0" encoding="UTF-8"?>
<link>
<machine>machine</machine>
<port>port</port>
</link>
Is this something like You were after?
Rgds,
<kimmo/>