Solved

XML - XSL case transformation

Posted on 2009-07-15
11
364 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
  • 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
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL (http://www.experts-exchange.com/articles/201/Handling-Date-and-Time-in-PHP-and-MySQL.html) several years ago, it seemed like now was a good time to updat…
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

829 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