Solved

change element name in source document

Posted on 2003-12-10
6
236 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API (http://dictionary.reference.com/browse/API?s=t) has made its way into the popular lexicon of the English language.  A few years ago, …
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.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

743 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now