topical media & game development
professional-xml-08-language-extending.xsl / xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:ex="urn:some-URI">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<msxsl:script language = "C#" implements-prefix = "ex">
<![CDATA[
string delim = " ";
public String upperCase(String value) {
return value.ToUpper();
}
public String firstToken(String value) {
string[] temp = value.Split(delim.ToCharArray());
return temp[0];
}
public String lastToken(String value) {
string[] temp = value.Split(delim.ToCharArray());
return temp[temp.Length-1];
} ]]>
</msxsl:script>
<xsl:template match="/">
<xsl:apply-templates select="//customer[@id='ANTON']/contact" />
</xsl:template>
<xsl:template match="contact">
<contact>
<fullName><xsl:value-of select="name" /></fullName>
<firstName><xsl:value-of select="ex:firstToken(name)" /></firstName>
<lastName><xsl:value-of select="ex:upperCase(ex:lastToken(name))" /></lastName>
</contact>
</xsl:template>
</xsl:stylesheet>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.