xsl-list
[Top] [All Lists]

Re: [xsl] Renaming an element when using copy-of

2006-06-20 07:25:57
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>