This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: collapsing consecutive elements


How would you reverse this process?

For example, transform

<db>
   <a_b_c>
      <d/>
      <e/>
   </a_b_c>

   <f_g_h>
      <i/>
      <j/>
   </f_g_h>
</db>

to

<db>
   <a>
      <b>
         <c>
            <d/>
            <e/>
         </c>
      </b>
   </a>

   <f>
      <g>
         <h>
            <i/>
            <j/>
         </h>
      </g>
   </f>
</db>

That seems to be a more difficult problem.

The following is my initial attempt.  It does not work.

<?xml version="1.0"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
                version="1.0">

<xsl:template match="*">

   <!-- only a default value for the binding -->
   <xsl:param name="x" select="{name()}"/>

   <xsl:if test="contains($x, '_and_'">

      <xsl:element name="{substring-before(name(), '_and_')}">
         <xsl:apply-templates>
            <xsl:with-param name="x" select="substring-after(name(), '_and_')">
         </xsl:apply-templates>
      </xsl:element>

   </xsl:if>

</xsl:template>

</xsl:stylesheet>

Many thanks,

Saverio Perugini


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]