xsl-list
[Top] [All Lists]

[xsl] an xsl transformation is missing an element from its output

2008-05-27 11:33:12
xsl processor: Saxon 8B
xsl version 2.0

This is my first attempt at using xsl to transform xml. Here is my input file:

<?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?

Thanks!
Tony Z.

--~------------------------------------------------------------------
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>
  • [xsl] an xsl transformation is missing an element from its output, Tony Zanella <=