Subject: [xsl] Copying and renaming an element/attribute From: "Mark Peters" <flickrmeister@xxxxxxxxx> Date: Sat, 8 Jul 2006 12:32:11 -0400 |
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.
<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>
<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.
<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>
Thanks in advance, Mark
Mark Peters Senior Technical Writer Saba Software
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] transform fails with para, Michael Kay | Thread | Re: [xsl] Copying and renaming an e, Mukul Gandhi |
Re: [xsl] Identity transform (case , Mukul Gandhi | Date | Re: [xsl] Copying and renaming an e, Mukul Gandhi |
Month |