Solved

change element name in source document

Posted on 2003-12-10
6
239 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
API Soap Calls 4 117
c# code 19 71
MS Access how to nest many values to one value when exporting query to XML format 8 55
what are list of ebay api errors 1 19
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
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.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

832 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