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 August 17th, 2004, 07:24 AM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default XSLT simple parsing problem

Hello. I have a simple question BUT for which I have not found yet any response.
I have to transform an XML file to another. Let's take a piece of the first XML file:

<ELEM1>some text1 <ELEM2> some text2 </ELEM2> some text3 </ELEM1>

and in the second XML file I want to result something like:

<ELEM1>some text1 <ELEM3> some text2 </ELEM3> some text3 </ELEM1>

Can anybody help me with a piece of xslt code which do this ???

Thanks in advance.


 
Old August 17th, 2004, 09:41 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post
Default

something like this maybe?
<xsl:template match="ELEM1">
    <xsl:copy>
        <xsl:apply-templates/>
    </xsl:copy>
</xsl:template>
<xsl:template match="ELEM2">
    <ELEM3>
        <xsl:value-of select="."/>
    </ELEM3>
</xsl:template>
 
Old August 17th, 2004, 11:25 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

The generic way is to use the identity transform which copies everything but include specific templates to match any special cases:
Code:
<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>
  <!--
    Templates to match nodes that need changing go here
  -->
<xsl:template match="ELEM2">
  <ELEM3>
    <xsl:apply-templates select="node()|@*"/>  
  </ELEM3>
</xsl:template>
</xsl:stylesheet>
Joe (MVP - xml)
 
Old August 18th, 2004, 02:00 AM
Registered User
 
Join Date: Aug 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi and thanks.
Being a junior xslt developper (2 days experience) this was very helpful.

Thanks again.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Parsing and counting using XSLT manish_jaiswal XSLT 2 January 24th, 2008 02:38 AM
Simple XSLT Problem (HELP PLEASE) gaeawalker XSLT 2 October 10th, 2007 10:27 AM
Urgent help regarding XSLT parsing.... to xml.. netbramha XSLT 1 September 19th, 2005 09:03 AM
Problem applying simple XSLT to XML to create CSV gregclark XSLT 2 August 25th, 2005 07:30 AM
Parsing an XSLT stylesheet failed .... :( Thebravehearth XML 0 October 12th, 2004 10:55 PM





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