Solved

XML - XSL case transformation

Posted on 2009-07-15
11
358 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

I will show you how to create a ASP.NET Captcha control without using any HTTP HANDELRS or what so ever. you can easily plug it into your web pages. For Example a = 2 + 3 (where 2 and 3 are 2 random numbers) Session("Answer") = 5 then we…
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
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…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now