Use translate() function and text() function to change the letter case : translate « XSLT stylesheet « XML

XML
1. CSS Style
2. SVG
3. XML Schema
4. XQuery
5. XSLT stylesheet
Java
XML Tutorial
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / C Sharp
C# / CSharp Tutorial
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
XML » XSLT stylesheet » translate 
Use translate() function and text() function to change the letter case

File: Data.xml

<?xml version="1.0"?>
<Employees>
  <Person>
    <FirstName>A</FirstName>
    <LastName>B</LastName>
    <DateOfBirth>2008-12-12</DateOfBirth>
  </Person>
  <Person>
    <FirstName>C</FirstName>
    <LastName>D</LastName>
    <DateOfBirth>2008-11-11</DateOfBirth>
  </Person>
  <Person>
    <FirstName>E</FirstName>
    <LastName>F</LastName>
    <DateOfBirth>2008-10-10</DateOfBirth>
  </Person>
</Employees>


File: Transform.xslt

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:template match="/">
    <html>
      <body>
        <xsl:apply-templates
          select="//text()[normalize-space(.)]" />
      </body>
    </html>
  </xsl:template>

  <xsl:template match="text()">
    <xsl:variable name="upper"
      select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
    <xsl:variable name="lower"
      select="'abcdefghijklmnopqrstuvwxyz'" />
    The input
    <span
      style="background-color: #c0c0c0;">
      <xsl:value-of select="." />
    </span>
    was translated to
    <span
      style="background-color: #ffd700;">
      <xsl:value-of select="translate(., $lower, $upper)" />
      <br />
    </span>
  </xsl:template>
</xsl:stylesheet>

Output:

<html>
   <body>
          The input
          <span style="background-color: #c0c0c0;">A</span>
          was translated to
          <span style="background-color: #ffd700;">A<br></span>
          The input
          <span style="background-color: #c0c0c0;">B</span>
          was translated to
          <span style="background-color: #ffd700;">B<br></span>
          The input
          <span style="background-color: #c0c0c0;">2008-12-12</span>
          was translated to
          <span style="background-color: #ffd700;">2008-12-12<br></span>
          The input
          <span style="background-color: #c0c0c0;">C</span>
          was translated to
          <span style="background-color: #ffd700;">C<br></span>
          The input
          <span style="background-color: #c0c0c0;">D</span>
          was translated to
          <span style="background-color: #ffd700;">D<br></span>
          The input
          <span style="background-color: #c0c0c0;">2008-11-11</span>
          was translated to
          <span style="background-color: #ffd700;">2008-11-11<br></span>
          The input
          <span style="background-color: #c0c0c0;">E</span>
          was translated to
          <span style="background-color: #ffd700;">E<br></span>
          The input
          <span style="background-color: #c0c0c0;">F</span>
          was translated to
          <span style="background-color: #ffd700;">F<br></span>
          The input
          <span style="background-color: #c0c0c0;">2008-10-10</span>
          was translated to
          <span style="background-color: #ffd700;">2008-10-10<br></span></body>
</html>

 
Related examples in the same category
1. translate function
2. Use translate function with if statement
www.java2java.com | Contact Us
Copyright 2010 - 2030 Java Source and Support. All rights reserved.
All other trademarks are property of their respective owners.