topical media & game development

talk show tell print

professional-xml-08-xsl2-functions.xsl / xsl



  <?xml version="1.0" encoding="UTF-8"?>
  <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:fn="http://www.w3.org/2005/xpath-functions" xmlns:xdt="http://www.w3.org/2005/xpath-datatypes" xmlns:ex="some-URI">
          <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" exclude-result-prefixes="fn xs xdt ex"/>
          <xsl:template match="/">
                  <contacts>
                          <xsl:apply-templates select="customers/customer/contact"/>
                  </contacts>
          </xsl:template>
          <xsl:template match="contact">
                  <contact>
                          <xsl:value-of select="ex:name-case(name)"/>
                  </contact>
          </xsl:template>
          <xsl:function name="ex:name-case" as="xs:string">
                  <xsl:param name="value" as="xs:string"/>
                  <xsl:sequence select="if(contains(value, ' '))
                                 then concat(substring-before(value, ' '), 
                                                      ' ', 
                                                                                     upper-case(substring-after(value, ' ')))
                                 else value"/>
          </xsl:function>
  </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.