xsl-list
[Top] [All Lists]

Re: Merging adjacent nodes of same type

2005-09-23 05:19:51

This is a fairly standard grpuping question (google your way to jeni's
site)

David,

Thanks for your informative answer and suggested template.

I've just tried it, but it doesn't appear to be working.  Here is what I
am using (modified slightly for my schema):

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:aston="http://www.aston.tv/schemas/Aston/Aston7";>

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

   <xsl:template match="node()">
       <xsl:copy>
           <xsl:copy-of select="@*"/>
           <xsl:apply-templates select="node()[1]"/>
       </xsl:copy>
       <xsl:apply-templates select="following-sibling::node()[1]"/>
   </xsl:template>

   <xsl:template match="aston:offset[not(node())]">
       <xsl:param name="a" select="/.."/>
       <xsl:choose>
           <xsl:when test="following-sibling::node()[self::* or
normalize-space(.)][1]/self::aston:offset[not(node())]">
               <xsl:apply-templates
select="following-sibling::aston:offset[1]">
                   <xsl:with-param name="a" select="$a|@*"/>
               </xsl:apply-templates>
           </xsl:when>
           <xsl:otherwise>
               <offset x="{sum($a[name()='x']|@x)}"
y="{sum($a[name()='y']|@y)}" z="{sum($a[name()='z']|@z)}"/>
               <xsl:apply-templates select="following-sibling::node()[1]"/>
           </xsl:otherwise>
       </xsl:choose>
   </xsl:template>

</xsl:stylesheet>

Here is the exact XML I am trying it on:

<text xmlns=\"http://www.aston.tv/schemas/Aston/Aston7\";>
   <offset x=\"0.1\" y=\"0\" z=\"0\" />
   <offset x=\"0.1\" y=\"0\" z=\"0\" />
   Aston Broadcast Systems Ltd.
</text>

Can you spot any obvious mistakes I may have made?

Regards,

Matt.


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