[xsl] trying to create surrounding element

Subject: [xsl] trying to create surrounding element
From: Andreas Peter <info@xxxxxxxxxx>
Date: Sun, 08 Jun 2008 18:59:55 +0200
Hello list users,

this is my xml file:

<?xml version="1.0" encoding="UTF-8"?>
<aaa>
   <bbb>
       <ccc>
           <ddd attribute="boxtype_start"/>
       </ccc>
       <eee>box1_start</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxh1"/>
       </ccc>
       <eee>1_boxtitle_h1</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxh2"/>
       </ccc>
       <eee>1_boxtitle_h2</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxpara"/>
       </ccc>
       <eee>boxpara</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxtype_end"/>
       </ccc>
       <eee>box1_end</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxtype_start"/>
       </ccc>
       <eee>box2_start</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxh1"/>
       </ccc>
       <eee>2_boxtitle_h1</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxh2">test</ddd>
       </ccc>
       <eee>2_boxtitle_h2</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxpara"/>
       </ccc>
       <eee>boxpara</eee>
   </bbb>
   <bbb>
       <ccc>
           <ddd attribute="boxtype_end"/>
       </ccc>
       <eee>box2_end</eee>
   </bbb>
</aaa>


This my xsl file:


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


<xsl:output indent="yes"/>

   <xsl:template match="/">
       <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="aaa">
       <xsl:apply-templates/>
   </xsl:template>

   <xsl:template match="bbb">
       <xsl:if test="descendant::*[@attribute='boxh1']">
           <title>
               <xsl:apply-templates select="eee"/>
           </title>
       </xsl:if>
       <xsl:if test="descendant::*[@attribute='boxh2']">
           <subtitle>
               <xsl:apply-templates select="eee"/>
           </subtitle>
       </xsl:if>
       <xsl:if test="descendant::*[@attribute='boxpara']">
           <para>
               <xsl:apply-templates select="eee"/>
           </para>
       </xsl:if>
   </xsl:template>

</xsl:stylesheet>

I am trying to create a surrounding element box, depending on the contents of the element <eee> (box1_start | box2_start) so that the result looks like the following:

<?xml version="1.0" encoding="UTF-8"?>
   <box> <!-- box1_start -->
   <title>1_boxtitle_h1</title>
   <subtitle>1_boxtitle_h2</subtitle>
   <para>boxpara</para>
   </box

   <box> <!-- box2_start -->
   <title>2_boxtitle_h1</title>
   <subtitle>2_boxtitle_h2</subtitle>
   <para>boxpara</para>
  </box>

I would be very thankful for any suggestions according to my problem.

Thanks in advance,
Andreas

Current Thread