[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

change element name in source document

Posted on 2003-12-10
6
Medium Priority
?
246 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

Tech or Treat!

Submit an article about your scariest tech experience—and the solution—and you’ll be automatically entered to win one of 4 fantastic tech gadgets.

Question has a verified solution.

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

Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

649 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