?
Solved

change element name in source document

Posted on 2003-12-10
6
Medium Priority
?
245 Views
Last Modified: 2013-11-19
Hi,

I need to change an element name in an xml source document.

The element is called <pgbrk/> and need to change it to <section/><section>.
But I need to change this only...and nothing else. the rest of the document needs to remain untouched.

I can then apply my other templates.
Thanks in advance

lk
0
Comment
Question by:leekey
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
dualsoul earned 600 total points
ID: 9919421
hm...try this XSLT snippet:
.............................
 <xsl:template match="pgbrk">
          <section>
                <xsl:apply-template /> <!-- apply other templates -->
          </section>
 </xsl:template>
 ...............................

or you can just copy all content of <pgbrk>...if you want it, like this:
.............................
 <xsl:template match="pgbrk">
          <section>
               <xsl:copy-of select="child::*" />          <!-- copy all nodes inside pgbrk-->
          </section>
 </xsl:template>
.............................................
0
 

Author Comment

by:leekey
ID: 9921651
Hi,

Thanks, but I need to change the <pgbrk/> in the source xml document.
then apply my standard templates to produce my html.

I can apply all my standard templates now but I need to have changed the name of
that element first. Also keep it where it appears in the source document.

Lk

0
 
LVL 26

Assisted Solution

by:rdcpro
rdcpro earned 600 total points
ID: 9922322
That's what dualsoul is talking about.  I assume you want to do this as a one-time deal, not do it each time you call your standard transform?  So when you're done, the original XML is saved with the section element.  

So this:

<root>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <pgbrk/>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <pgbrk/>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
</root>

becomes this:

<root>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <section/>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <section/>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
</root>

Or do you want to enclose the nodes between each pair of <pgbrk> elements in a <section></section> element like:

<root>
  <section>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
  </section>
  <section>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
  </section>
  <section>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
    <foo>Bar</foo>
  </section>
</root>

If that's the case, and you were thinking of inserting this:

</section>
<section>

where a <pgbrk> occurs, and inserting a <section> at the beginning, and a </section> at the end...then you are going about it wrong.  This example shows you how to do XPath based grouping:

http://dev.rdcpro.com/Members/rdcpro/snippets/xpathgrouping/


Regards,
Mike Sharp
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 9923227
leekey, so may be you post your xml, and result you want to get?
so we can understand your problem more clearly...
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
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.
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…
Suggested Courses

764 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