Solved

XML - XSL case transformation

Posted on 2009-07-15
11
365 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
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 arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

733 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