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

Re: Copying and renaming an element/attribute

Subject: Re: Copying and renaming an element/attribute
From: "Mark Peters" <flickrmeister@xxxxxxxxx>
Date: Sat, 8 Jul 2006 13:33:34 -0400
Re:  Copying and renaming an element/attribute
Amazing, Mukul! How did you work that out so quickly?

Many thanks.
Mark


On 7/8/06, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
Hi Mark,
 Please try this stylesheet:

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="xml" indent="yes" />

  <xsl:template match="topic">
    <topicref href="{@id}">
      <xsl:apply-templates />
    </topicref>
  </xsl:template>

<xsl:template match="text()" />

</xsl:stylesheet>

Regards,
Mukul

On 7/8/06, Mark Peters <flickrmeister@xxxxxxxxx> wrote:
> Hi Folks,
>
> I'm trying to copy a single element ("topic") and attribute ("id") to
> a new XML file, discarding all other elements and attributes. I'd also
> like to rename the topic element as topicref, and rename the id
> attribute as href.
>
>
> Input XML:
>
> <topic id="unique_id">
>        <title>Title</title>
>        <body>
>                <p>Some text.</p>
>        </body>
>        <topic id="unique_id">
>                <title>Title</title>
>                <body>
>                        <p>Some text.</p>
>                </body>
>        </topic>
>        <topic id="unique_id">
>                <title>Title</title>
>                <body>
>                        <p>Some text.</p>
>                </body>
>                <topic id="unique_id">
>                        <title>Title</title>
>                        <body>
>                                <p>Some text.</p>
>                        </body>
>                </topic>
>        </topic>
> </topic>
>
>
>
> Output XML:
>
> <topicref href="unique_id">
>        <topicref href="unique_id"/>
>        <topicref href="unique_id">
>                <topicref href="unique_id"/>
>        </topicref>
> </topicref>
>
>
> I've tried various value-of statements, which result in a simple list
> of topicref elements. The elements aren't nested. I'm trying to keep
> the original nesting.
>
> I've also tried xsl:copy (see below), but the output file only
> displays the first topic element. From what I've been reading, I think
> "topic" as an XPath statement should find all instances of that
> element -- although I've tried a few different XPath patterns, without
> success.
>
>
> Stylesheet:
>
> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
>        <xsl:output method="xml" version="1.0" encoding="utf-8" indent="yes"/>
>        <xsl:template match="node()|@*">
>                <xsl:copy>
>                        <xsl:apply-templates select="@*"/>
>                        <xsl:apply-templates/>
>                </xsl:copy>
>        </xsl:template>
>        <xsl:template match="topic">
>                <topicref>
>                                        <xsl:attribute name="href">
>                        <xsl:for-each select="@id">
>                                <xsl:value-of select="."/>
>                        </xsl:for-each>
>                                         </xsl:attribute>
>                </topicref>
>        </xsl:template>
> </xsl:stylesheet>
>
>
>
> Could someone tell me what I'm missing?
>
> Thanks in advance,
> Mark
>
> --
>
> Mark Peters
> Senior Technical Writer
> Saba Software




--

Mark Peters
Senior Technical Writer
Saba Software

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.