Language switcher for Umbraco

Modified on 2011/04/09 11:33 by Jovall — Categorized as: Uncategorized

XSLT by lordtoro

    <?xml version=”1.0″ encoding=”UTF-8″?>
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY nbsp " ">
    ]>
    <xsl:stylesheet
     version=”1.0″
     xmlns:xsl=”http://www.w3.org/1999/XSL/Transform“
     xmlns:msxml=”urn:schemas-microsoft-com:xslt”
     xmlns:user=”user-scripts”
     xmlns:umbraco.library=”urn:umbraco.library”
     xmlns:Exslt.ExsltCommon=”urn:Exslt.ExsltCommon”
     xmlns:Exslt.ExsltDatesAndTimes=”urn:Exslt.ExsltDatesAndTimes” 
     xmlns:Exslt.ExsltMath=”urn:Exslt.ExsltMath”
     xmlns:Exslt.ExsltRegularExpressions=”urn:Exslt.ExsltRegularExpressions”
     xmlns:Exslt.ExsltStrings=”urn:Exslt.ExsltStrings” 
     xmlns:Exslt.ExsltSets=”urn:Exslt.ExsltSets” 
     exclude-result-prefixes=”msxml umbraco.library 
                 Exslt.ExsltCommon 
                 Exslt.ExsltDatesAndTimes 
                 Exslt.ExsltMath 
                 Exslt.ExsltRegularExpressions 
                 Exslt.ExsltStrings Exslt.ExsltSets “>

    <xsl:output method=”xml” omit-xml-declaration=”yes”/>
    <xsl:param name=”currentPage” />
    <xsl:template match=”/”>
       <form name=”myForm”>         
          <select id=”langselection” 
                  name=”langselection” 
                  onchange=”loadPage(this.form.elements[0])” 
                  target=”_parent._top” >
             <xsl:for-each select=”$currentPage/ancestor::root/node”>
                <xsl:if test=”@nodeTypeAlias =’HomePage’”>                                   
                   <xsl:choose>    
                      <xsl:when test=”@id = $currentPage/ancestor-or-self::node[last()]/@id”> 
                         <option value=”{umbraco.library:NiceUrl(@id)}” selected=”selected”>
                            <xsl:value-of select=”data [@alias = 'siteLanguage']“/>
                         </option>                       
                       </xsl:when>
                       <xsl:otherwise>
                          <option value=”{umbraco.library:NiceUrl(@id)}” >
                             <xsl:value-of select=”data [@alias = 'siteLanguage']” />
                          </option>
                       </xsl:otherwise>
                    </xsl:choose>                  
                 </xsl:if>
              </xsl:for-each>
           </select>
        </form>
     </xsl:template>
     </xsl:stylesheet>