[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Renaming an element when using copy-of

Subject: Re: Renaming an element when using copy-of
From: Chad Chelius <cchelius@xxxxxxxxxxxxxxx>
Date: Tue, 20 Jun 2006 10:28:01 -0400
xsl copy apply template
Thanks for your reply Michael and to all others as well. I'm still having trouble with this issue, so I decided to include the files that I'm working with (content has been changed to protect the innocent). As you will probably notice by looking at my XSLT, I am a definite newbie. So if anyone has any recommendations or looks at it and says "Whoa, you are way off base here!" I can take it, please offer your advice. Basically, I am having difficulties with the <author> section of the xslt. It is currently doing what I want, however I need <author> to show up as <Author>. Seems very basic, but I am having great difficulties accomplishing this in my xslt. So here are the files below, thanks in advance for everyones help.

My XML file:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Root>
<Story>
<articleTitle>Title </articleTitle>
<articleSubTitle>Subtitle </articleSubTitle>
<author><authorFname>Jane</authorFname>
<authorLname>Doe</authorLname>, <authorDegree>RN, MPS</ authorDegree>
</author>
<author><authorFname>John</authorFname>
<authorLname>Doe</authorLname>, <authorDegree>MD</ authorDegree>
</author>
<abstract_body>
<italic>Miscellaneous Text Goes Here </italic>
</abstract_body>
<subHead>Subhead </subHead>
<body_text>Body Text goes here: </body_text>
<body_text>Body Text. </body_text>
</Story>
<Source><PublisherName>Publishing Inc</ PublisherName><Publication>My Very Special Journal </ Publication><Issn>1234-5678 </Issn><Date>
<Month>July</Month>
<Year>2006</Year>
</Date>Volume <Volume>12</Volume>
<Issue>Issue <IssuePart>8</IssuePart>
</Issue>Pages <Pages>9ndash;22 </Pages><FirstPage>97</ FirstPage><Pages
> </Pages><LastPage>109</LastPage><Pages> </Pages></Source>
<department>Department: My Department</department>
</Root>


My XSLT:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<!-- Set the destination document to XML format and apply indenting to make it easier to read -->
<xsl:output method="xml" indent="yes"/>
<xsl:template match="Root">
<ArticleSet>
<Article>
<Journal>
<PublisherName>
<xsl:apply-templates select="Source/ PublisherName"/>
</PublisherName>
<JournalTitle>
<xsl:apply-templates select="Source/ Publication"/>
</JournalTitle>
<Issn>
<xsl:apply-templates select="Source/Issn"/>
</Issn>
<Volume>
<xsl:apply-templates select="Source/Volume"/>
</Volume>
<Issue>
<xsl:apply-templates select="Source/Issue"/>
</Issue>
<PubDate>
<Year>
<xsl:apply-templates select="Source/Date/ Year"/>
</Year>
<Month>
<xsl:apply-templates select="Source/Date/ Month"/>
</Month>
</PubDate>
</Journal>
<ArticleTitle>
<xsl:apply-templates select="Story/articleTitle"/ >. <xsl:apply-templates
select="Story/articleSubTitle"/>
</ArticleTitle>
<FirstPage>
<xsl:apply-templates select="Source/FirstPage"/>
</FirstPage>
<LastPage>
<xsl:apply-templates select="Source/LastPage"/>
</LastPage>
<!-- This is the section were I want <author> to be <Author> -->
<AuthorList>
<!-- <Author>-->
<xsl:copy-of select="Story/author"/>- <!-- </ Author> -->
</AuthorList>
<Abstract>
<xsl:apply-templates select="Story/abstract_body"/>
</Abstract>
</Article>
</ArticleSet>
</xsl:template>
</xsl:stylesheet>


On Jun 13, 2006, at 4:03 PM, Michael Kay wrote:

You can't do it using xsl:copy-of. Instead you walk the tree using
xsl:apply-templates, changing the name of each node as you go. If there are
nodes you don't want to change, you can handle them with an identity
template:


<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

and then you just write additional rules for the nodes you do want to
change.

Michael Kay

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.