[Home] [By Thread] [By Date] [Recent Entries]
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 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
|

Cart



