Solved

XML - XSL case transformation

Posted on 2009-07-15
11
366 Views
Last Modified: 2013-11-18
Hello Experts,

<code> XXXX<code>

I want apply XSL to change the case to:

<Code> XXXX<Code>
0
Comment
Question by:mani_sai
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
  • 2
11 Comments
 
LVL 11

Expert Comment

by:kmartin7
ID: 24864130
I am sure you are actually asking for more than what your question asks for, but here is a template that will do exactly what you are asking:

<xsl:template match="case">
     <Case><xsl:apply-templates /></Case>
<xsl:template>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24864131
Do you want to do that to all the tags?
Or just to <code>?
0
 
LVL 11

Assisted Solution

by:kmartin7
kmartin7 earned 200 total points
ID: 24864148
Or more accurately, assuming there will not be any children elements within <case>:

<xsl:template match="case">
     <Case><xsl:value-of select="."  /></Case>
<xsl:template>
0
The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24864174
This stylesheet will make an identity copy of your source XML
but will uppercase each first character of the name
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:template match="*">
    <xsl:variable name="new-element-name">
        <xsl:value-of select="translate(substring(name(), 1, 1), 'azertyuiopqsdfghjklmwxcvbn', 'AZERTYUIOPQSDFGHJKLMWXCVBN')"/>
        <xsl:value-of select="substring(name(), 2)"/>
    </xsl:variable>
    <xsl:element name="{$new-element-name}">
        <xsl:copy-of select="@*"/>
        <xsl:apply-templates select="node()"/>
    </xsl:element>
</xsl:template>
</xsl:stylesheet>

Open in new window

0
 
LVL 8

Author Comment

by:mani_sai
ID: 24864182

this is my XML after applying XSL:
<codes>
<code>
  <value>BU00</value>
  <desc>DBA</desc>
  </code>
<code>
  <value>BU01</value>
  <desc>Growth Strategies/Tactics</desc>
  </code>
  </codes>
 
i want this to be:  
 

<Codes>
<Code>
  <Value>BU00</Value>
  <Desc>DBA</Desc>
  </Code>
<Code>
  <Value>BU01</Value>
  <Desc>Growth Strategies/Tactics</Desc>
  </Code>
  </Codes>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24864198
I believe that kmartin7 means

<xsl:template match="code">
     <Code><xsl:value-of select="."  /></Code>
<xsl:template>

if this is about your previous question,
you can of course simply make the tag correct, immedeatly in your XSLT
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24864214
yep, you have literal output elements in your xslt, just change them there,
and they will come out right in the output, directly
0
 
LVL 8

Author Comment

by:mani_sai
ID: 24864239
Gertone:
Cool, i will try your code and let you know.
If I have a word like this:
<application data> kkkk</application data>
 i need the text to be changed to:
</Application Data> kkkk< </Application Data>
 
 
0
 
LVL 60

Accepted Solution

by:
Geert Bormans earned 300 total points
ID: 24864242
just to clarify,
in my last XSLT in your previous question,
you hav ethis
    <xsl:template match="Table/*[starts-with(name(), 'VALUE_')]">
        <code>
            <value><xsl:value-of select="."/></value>
            <desc><xsl:value-of select="following-sibling::DESCRIPTION[1]"/></desc>
        </code>
    </xsl:template>
make it
    <xsl:template match="Table/*[starts-with(name(), 'VALUE_')]">
        <Code>
            <Value><xsl:value-of select="."/></Value>
            <Desc><xsl:value-of select="following-sibling::DESCRIPTION[1]"/></Desc>
        </Code>
    </xsl:template>
0
 
LVL 60

Expert Comment

by:Geert Bormans
ID: 24864247
<application data> kkkk</application data>
that is simply illegal XML
you can't have spaces in the element names
0
 
LVL 8

Author Closing Comment

by:mani_sai
ID: 31603993
Thanks to both of you.
0

Featured Post

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

691 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question