Solved

change element name in source document

Posted on 2003-12-10
6
241 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
  • 2
6 Comments
 
LVL 15

Accepted Solution

by:
dualsoul earned 150 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 150 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

Suggested Solutions

Title # Comments Views Activity
Word files to Wordpress Posts 2 64
Automating receiving uploaded files via HTTPS instead of SFTP 3 59
Post xml via PHP Soap Client 3 61
what are list of ebay api errors 1 28
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
The viewer will learn how to dynamically set the form action using jQuery.
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…

856 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