Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 27th, 2006, 01:53 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Transform XML to XML

Hi,

I want to transform my XML file. From somethings like:

<book>
<title>Java security</title>
<code>005.8 MCGR </code>
<author>Gary & Edward</author>
<content>
<chapters>Why Java security is important </chapters>
<chapters>The Java Security Model</chapters>
....
</content>
<published>1997</published>
<status>
<available>No</available>
<reserved>No</reserved>
</status>
....
</book>

to become something like this:
<book>
<title>Java security</title>
<code>005.8 MCGR </code>
<author>Gary & Edward</author>
<content>
<chapter>Why Java security is important </chapter>
<chapter>The Java Security Model</chapter>
....
</content>
<published>1997</published>
....
</book>

In short, I want to change <chapters> to <chapter> and I want to eliminate <status> tag.

I'm new to XSLT. So, this question might be among one of the very first questions.
Any help would be appreciated. Thank you.

PS. I'm using XSLT 1.0

 
Old April 27th, 2006, 02:14 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>In short, I want to change <chapters> to <chapter>

<xsl:template match="chapters">
<chapter>
  <xsl:apply-templates/>
</chapter>
</xsl:template>

 and I want to eliminate <status> tag.

<xsl:template match="status"/>

and you want to copy everything else unchanged:

<xsl:template match="*">
<xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
</xsl:copy>
</xsl:template>


Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 27th, 2006, 05:14 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's really work!
Thank you very much. =)

 
Old May 4th, 2006, 11:10 PM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi,

I have a smilar problem where I'd like to transform from Reporting Services XML to eliminate a tag.

The original XML is:

<?xml version="1.0"?>
<Report xmlns="UC203_x0020_Export_x0020_Returning_x0020_Of ficer_x0020_Details_x0020_for_x0020_Advertising" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="UC203_x0020_Export_x0020_Retur ning_x0020_Officer_x0020_Details_x0020_for_x0020_A dvertising http://localhost/reportserver/folder?%2fUC203+Export+Returning+Officer+Details+f or+Advertising&amp;ElectionEventID=dee73101-8b80-4cae-8c15-e6fed571dfa2&amp;ElectorateTypeID=00000001-0001-0001-0001-000000000006&amp;rs%3aFormat=XML&amp;rs%3aShowHide Toggle%3aisnull=True&amp;rc%3aSchema=True" Name="UC203 Export Returning Officer Details for Advertising">
    <ReturningOfficers>
        <ReturningOfficerDetails_Collection>
            <ReturningOfficerDetails>
                <Electorate>Ballajura</Electorate>
                <RO>Tom Jones</RO>
                <Tel>92913336</Tel>
                <Mob> </Mob>
                <Venue>Ballajura Community College</Venue>
                <Address1>Illawarra Crescent South</Address1>
                <Address2> </Address2>
                <Suburb>BALLAJURA</Suburb>
            </ReturningOfficerDetails>
        </ReturningOfficerDetails_Collection>
    </ReturningOfficers>
</Report>

The ReturningOfficerDetails_Collection and Report tags are to be removed so that the output then becomes:

<?xml version="1.0"?>
<ReturningOfficers>
   <ReturningOfficerDetails>
    <Electorate>Ballajura</Electorate>
    <RO>Tom Jones</RO>
    <Tel>92913336</Tel>
    <Mob> </Mob>
    <Venue>Ballajura Community College</Venue>
    <Address1>Illawarra Crescent South</Address1>
    <Address2> </Address2>
    <Suburb>BALLAJURA</Suburb>
   </ReturningOfficerDetails>
</ReturningOfficers>

Thanks
 
Old May 5th, 2006, 02:34 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

izbor, please raise your problem in a new thread. I can't see any relationship to the original topic of the thread, and the topics are going to become hopelessly entangled if they are on the same thread.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 5th, 2006, 02:43 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ha Ha good joke - not!

Of course they are related - the thread is about transforming XML

Will you just answer the question or will we carry a pedantic tit for tat

 
Old May 5th, 2006, 02:46 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

izbor, if you treat me like that, then you will certainly not get any help from me.

This whole forum is about transforming XML to XML using XSLT. If you had any experience using such forums, let alone answering questions raised on them, you would know how important it is to structure the information clearly.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old May 5th, 2006, 02:48 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Quote:
quote:Originally posted by izbor


Will you just answer the question or will we carry a pedantic tit for tat
Don't hold your breath...

--

Joe (Microsoft MVP - XML)
 
Old May 5th, 2006, 03:08 AM
Registered User
 
Join Date: May 2006
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I hate these forums :(

Sorry for yanking your chain. Mine has been yanked a few times this week.

The thread title got me.










Similar Threads
Thread Thread Starter Forum Replies Last Post
Transform xml to xml changing one tag. surfer97301 XSLT 2 April 21st, 2010 05:14 PM
XML to XML transform (Simplified) nmahesh567 XSLT 2 March 24th, 2007 07:57 AM
XSLT read through XML to transform another XML dendenx2 XSLT 8 July 7th, 2005 08:18 PM
Transform XML to XML wene XSLT 8 December 17th, 2004 11:28 AM
Transform XML to XML using XSLT Mr.D XSLT 2 September 7th, 2004 02:13 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.