Solved

XML - XSL case transformation

Posted on 2009-07-15
11
360 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

910 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

25 Experts available now in Live!

Get 1:1 Help Now