473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

xml -> xml using xslt

Hi,

I have an XML-file :
<book>
<title>Alaska</title>
</book>

I would like transfer the <book>-elements to <bookname> using an xsl-sheet,
thus producing xml-again. and saving the output in a new xml-file

how can I achieve this ? I don't know how to setup my select-statements
(????) :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select=???? >
<xsl:value-of select=???? />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

another question : is there a way to transform element-tags to uppercase ?

thnx

Chris
Nov 12 '05 #1
3 1259


Chris wrote:

I have an XML-file :
<book>
<title>Alaska</title>
</book>

I would like transfer the <book>-elements to <bookname> using an xsl-sheet,
thus producing xml-again. and saving the output in a new xml-file

how can I achieve this ?


Start with the identity transformation

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()" />
</xsl:copy>
</xsl:template>

and add a template for <book> elements

<xsl:template match="book">
<bookname>
<xsl:apply-templates select="@* | node()" />
<bookname>
</xsl:template>

--

Martin Honnen
http://JavaScript.FAQTs.com/
Nov 12 '05 #2
Chris,

I'm only a beginner with xslt so I'm sure that Martins way is a lot more
efficient than mine. Anyway, here is the xslt code you need:

Pete
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-16" indent="yes"/>

<xsl:template match="/book">
<booklist>
<xsl:for-each select="./title">
<new-title>
<xsl:value-of select="."></xsl:value-of>
</new-title>
</xsl:for-each>
</booklist>
</xsl:template>

</xsl:stylesheet>


"Chris" <ch********@pandora.be> wrote in message
news:Aj*******************@phobos.telenet-ops.be...
Hi,

I have an XML-file :
<book>
<title>Alaska</title>
</book>

I would like transfer the <book>-elements to <bookname> using an xsl-sheet, thus producing xml-again. and saving the output in a new xml-file

how can I achieve this ? I don't know how to setup my select-statements
(????) :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select=???? >
<xsl:value-of select=???? />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

another question : is there a way to transform element-tags to uppercase ?

thnx

Chris

Nov 12 '05 #3
Hi Chris

For your second point, you can use the translate() and name() functions to
do this. Here's a stylesheet that starts with the Identity transform (lots of
posts about this in this group), adds in another template that matches
elements, then translates the lower case letters to upper case. If you are
working with languages other than English, then you would need to expand the
list appropriately...

HTH

Nigel Armstrong

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >

<xsl:template match="/ | @* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*">
<xsl:element name="{translate(name(), 'abcdefghijklmnopqrstuvwxyz',
'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}">
<xsl:apply-templates select="@* | node()"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>


"Chris" wrote:
Hi,

I have an XML-file :
<book>
<title>Alaska</title>
</book>

I would like transfer the <book>-elements to <bookname> using an xsl-sheet,
thus producing xml-again. and saving the output in a new xml-file

how can I achieve this ? I don't know how to setup my select-statements
(????) :
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<xsl:for-each select=???? >
<xsl:value-of select=???? />
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

another question : is there a way to transform element-tags to uppercase ?

thnx

Chris

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: titanandrews | last post by:
Hi, I have ran into a situation that I think should be possible, but I am fairly new to XSLT so maybe not. Suppose I have the following document <ROOT> <FOO name="A"> <CHILD name="B"/>...
2
by: Sylvia | last post by:
Hi, I'm trying to render a XML structure to HTML using XSLT. My XML describe the header of a table with a complex and not linear structure. The first row of the header table always contains the...
2
by: Allan Bredahl | last post by:
Hi All I'm trying hard to find out how to transform XML to HTML using XSLT files. I have searched all over for some examples on how to do this, but I have had no succes with any of them. ...
5
by: Fred | last post by:
Not much expertise on XSLT and trying to understand it's uses when creating apps in VS.NET? If I wanted flexibility on the UI (View aspect of M.V.C.): - How does it compare with creating...
3
by: Jarek Mielcarek | last post by:
hi all, in xml file I have some fields which are source for <textarea> element. I'd like to transform this file using xslt and set the rows property of <textarea> depend of lines in some source...
1
by: basavaraj koti | last post by:
I need to show image using xslt Below provided in my xml and xslt. <?xml version="1.0" encoding="iso-8859-1"?> <?xml-stylesheet type="text/xsl" href="../xyz.xsl"?> <Grade class="03"...
3
by: WideBoy | last post by:
Hi, I have a software generated schema which creates a few empty elements, e.g. <xsd:sequence/>. I would like to be able to delete these elements from the schema post-generation using XSLT. ...
6
by: kluge.wolfram | last post by:
Hi, i get stucked on a transformation problem using XSLT. What i need is to copy an XML Tree to an output XML without any automatic changes. Since i used <xsl:copyor <xsl:copy-ofthere occur...
1
by: saritha2008 | last post by:
Hi, I have to convert the following Input xml code to output xml code using xslt. Can any one please help on escaping single quotation present in the input xml file in my xslt? ...
0
by: Prashant M | last post by:
Hi All, I had created a XSLT which converts the XML file generated from the system to the excel format. The XSLT has the styles required for this transformation. Now i am told to insert image...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.