Subject: Re: [xsl] an xsl transformation is missing an element from its output From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Tue, 27 May 2008 16:15:59 -0400 |
<?xml version="1.0" encoding="UTF-8"?> <test> <div1> <ptr target="a" n="2"/> <ptr target="b" n="15"/> </div1> <div1> <ptr target="c" n="72"/> <ptr target="d" n="3822"/> <ptr target="e" n="3823"/> </div1> </test>
Here is my stylesheet:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="no" encoding="utf-8" media-type="text/xml"
doctype-public="-//TEI P4//DTD Main Document Type//EN"/>
<xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()"/> </xsl:copy> </xsl:template>
<xsl:template match="div1"> <xsl:for-each select="ptr"> <xsl:element name="ptr"> <xsl:attribute name="target" select="@target"/> <xsl:attribute name="n" select="position()"/> </xsl:element> </xsl:for-each> </xsl:template>
</xsl:stylesheet>
When I run the transformation, here is the output I get:
<?xml version="1.0" encoding="utf-8"?><test> <ptr target="a" n="1"/><ptr target="b" n="2"/> <ptr target="c" n="1"/><ptr target="d" n="2"/><ptr target="e" n="3"/> </test>
All attributes within the ptr element are exactly as I want them. But I also want to preserve the div1 element tags in the output. Why are they not showing up, and how can I get the desired result?
<xsl:template match="div1"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:for-each select="ptr"> <xsl:element name="ptr"> <xsl:attribute name="target" select="@target"/> <xsl:attribute name="n" select="position()"/> </xsl:element> </xsl:for-each> </xsl:copy> </xsl:template>
<xsl:template match="ptr"> <ptr target="{@target}" n="{count(.|preceding-sibling::ptr)}"/> </xsl:template>
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] an xsl transformation is miss, Tony Zanella | Thread | [xsl] Re: element in most preferred, Jack Bates |
[xsl] Getting average, Chaudhary, Harsh | Date | Re: [xsl] Getting average, Wendell Piez |
Month |