0

I have the below XML which contains all the elements in lowercase.

<data>
    <employee>
        <id>2784</id>
        <employeeFirstName></employeeFirstName>
        <employeeLastName nil="true"/></employeeLastName>
    </employee>
</data>

Here my requirement is to convert all the elements to uppercase.

<DATA>
        <EMPLOYEE>
            <ID>2784</ID>
            <EMPLOYEEFIRSTNAME></EMPLOYEEFIRSTNAME>
            <EMPLOYEELASTNAME nil="true"/></EMPLOYEELASTNAME>
        </EMPLOYEE>
</DATA>

Anyone please help me to convert this xml using XSLT.

J.P
  • 495
  • 1
  • 6
  • 15
  • Please select either XSLT 1.0 or 2.0, not both - makes a **big** difference in this case. -- Also, I believe this is not the first question about converting case - why don't you do a search. – michael.hor257k Jul 19 '16 at 10:05
  • @JayP Your input is also not well formed. Check `employeeLastName` element – nawazlj Jul 19 '16 at 10:15
  • @michael.hor257k I am new to XSLT. I spent 2 hours for googling but I could't come up with the expected answer. This is the reason I asked the question in this forum. – J.P Jul 19 '16 at 10:19
  • Please answer the question regarding your XSLT version. If you don't know, see how to get it here: http://stackoverflow.com/questions/25244370/how-can-i-check-which-xslt-processor-is-being-used-in-solr/25245033#25245033 – michael.hor257k Jul 19 '16 at 10:21
  • This is no way to learn a language: spend two hours googling, then ask for help on StackOverflow. After two hours googling you haven't even learnt what search terms to use to find the information you need. Get yourself a good book and devote at least a day to reading it. – Michael Kay Jul 19 '16 at 14:56

2 Answers2

1

In XSLT 2.0, this is rather trivial:

<xsl:stylesheet version="1.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:strip-space elements="*"/>

<xsl:template match="*">
    <xsl:element name="{upper-case(name())}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates/>
    </xsl:element>
</xsl:template>

</xsl:stylesheet>
michael.hor257k
  • 113,275
  • 6
  • 33
  • 51
0

Simplest way to do in XSLT 1.0

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XS/Transform" version="1.0">
    <xsl:output method="xml" indent="yes" omit-xml-declaration="yes"/>
    <xsl:strip-space elements="*"/>
    <xsl:template match="node()|@*">
        <xsl:copy>
            <xsl:apply-templates select="node()|@*"/>
        </xsl:copy>
    </xsl:template>
    <xsl:template match="*">
        <xsl:element name="{
            translate(name(.),
            'abcdefghijklmnopqrstuvwxyz',
            'ABCDEFGHIJKLMNOPQRSTUVWXYZ')}">
            <xsl:apply-templates select="node()|@*"/>
        </xsl:element>
    </xsl:template>
</xsl:stylesheet>

It will produce the below output

<DATA>
    <EMPLOYEE>
        <ID>2784</ID>
        <EMPLOYEEFIRSTNAME/>
        <EMPLOYEELASTNAME nil="true"/>
    </EMPLOYEE>
</DATA>
nawazlj
  • 779
  • 8
  • 18
  • **1.** This doesn't work, because you have a typo in the xsl namespace. -- **2.** More importantly, you have two templates matching the same nodes with the same priority - so the result could be anything, depending on the processor's whim. – michael.hor257k Jul 19 '16 at 10:40