xsl-list
[Top] [All Lists]

RE: [xsl] XSLT: Transforming one markup to another markup

2006-05-02 08:33:25
2)In Y Markup--- always the last hierlev element contains two  hierlev

as children.
Michel Kay's Reply:

But that doesn't make sense. If the last hierlev element has two
hierlev children, then it's not the last hierlev 
element, because its children come after it. 

That makes sense to me but unfortunately the business rules are not
always logical for programming.According to business rules... All the
classitems are mapped to hierlev elements.Now the last hierlev child is
hierlev child(heading-> Title-> Manufacturing).
Then the next step is to add two hierlev children to the last hirelev
child. After this step the hierlev element which contains
"Manufacturing" is no more last child.The last node structure is as
follows:

 hierlev child(heading-> Title-> Manufacturing
       - hierlev child(heading-> Title-> Infobase Title
       - hierlev child(heading-> Title-> Title Value


The class item is a child of info element.The following template is
called in my main template with proper parameters, the following
template generates Y markup(i.e working fine).The following code assumes
the classitem depth as 4, but if the depth is more than 4, the following
code does not work. I need a solution for arbitary depth.

<xsl:template match="info/class[1]">
        <xsl:param name="role" />
        <xsl:param name="ancestorCount"/>
        <xsl:param name="nestedContent" />
                <xsl:param name="newRole" />
                <xsl:param name="markerValue"/>

                <xsl:param name="v1"
select="descendant::class[1]/text()"/>
        <xsl:param name="v2" select="descendant::class[2]/text()"/>
        <xsl:param name="v3" select="descendant::class[3]/text()"/>
        <xsl:param name="v4" select="descendant::class[4]/text()"/>


                <xsl:call-template name="createHierLevElement">
                    <xsl:with-param name="roleContent"
select="'ancestor'" />
                            <xsl:with-param name="hierLevContent">
                                <xsl:element name="heading">
                                                <xsl:element
name="title">
                                                           <xsl:copy-of
select="$v1"/> 
                                         </xsl:element>
                                 </xsl:element>
                                          <xsl:if test = "$ancestorCount
= 3">
                                            <xsl:call-template
name="createHierLevElement">
                                          <xsl:with-param
name="roleContent" select="'ancestor'" />
                                          <xsl:with-param
name="hierLevContent">
                                                 <xsl:element
name="heading">
                                             <xsl:element name="title">

                                    <xsl:copy-of select="$v2"/> 
                                                 </xsl:element>
                                              </xsl:element>
                                              <xsl:call-template
name="createHierLevElement">
                                             <xsl:with-param
name="roleContent" select="'ancestor'" />
                                             <xsl:with-param
name="hierLevContent">
                                                        <xsl:element
name="heading">
        
<xsl:element name="title">
        
<xsl:copy-of select="$v3"/> 
                                                        </xsl:element>
                                                         </xsl:element>
        
<xsl:call-template name="createHierLevElement">
                                                       <xsl:with-param
name="roleContent" select="'ancestor'" />
                                                       <xsl:with-param
name="hierLevContent">
                                                            <xsl:element
name="heading">
        
<xsl:element name="title">
        
<xsl:copy-of select="$v4"/> 
        
</xsl:element>
        
</xsl:element>
                                         <xsl:call-template
name="createHierLevNew">
                                              <xsl:with-param
name="roleContent" select="'ancestor'" />
        
<xsl:with-param name="newRole" select="$role"/>
        
<xsl:with-param name="marker" select="$markerValue"/>
        
</xsl:call-template>
        
</xsl:with-param>
                                                    </xsl:call-template>
                                                  </xsl:with-param>
                                          </xsl:call-template>
                                                </xsl:with-param>
                      </xsl:call-template>
                     </xsl:if>
                     <xsl:if test=" $ancestorCount = 2 ">
                                           <xsl:call-template
name="createHierLevElement">
                                          <xsl:with-param
name="roleContent" select="$role" />
                                          <xsl:with-param
name="hierLevContent">
                                                   <xsl:element
name="heading">
                                             <xsl:element name="title">

                                    <xsl:copy-of select="$v2"/> 
                                                 </xsl:element>
                                                  </xsl:element>
                                                  <xsl:call-template
name="createHierLevElement">
                                                <xsl:with-param
name="roleContent" select="$role" />
                                                 <xsl:with-param
name="hierLevContent">
                                                        <xsl:element
name="heading">
        
<xsl:element name="title">
        
<xsl:copy-of select="$v3"/> 
                                                        </xsl:element>
                                                         </xsl:element>
        
<xsl:call-template name="createHierLevNew">
                                              <xsl:with-param
name="roleContent" select="'ancestor'" />
        
<xsl:with-param name="newRole" select="$role"/>
        
<xsl:with-param name="marker" select="$markerValue"/>
        
</xsl:call-template>

                                                    </xsl:with-param>
                                              </xsl:call-template>
                                                  </xsl:with-param>
                      </xsl:call-template>
                     </xsl:if>
                    <xsl:if test=" $ancestorCount = 2 ">
                                            <xsl:call-template
name="createHierLevElement">
                                          <xsl:with-param
name="roleContent" select="$role" />
                                          <xsl:with-param
name="hierLevContent">
                                                  <xsl:element
name="heading">
                                             <xsl:element name="title">

                                    <xsl:copy-of select="$v2"/> 
                                                 </xsl:element>
                                                  </xsl:element>
                               <xsl:call-template
name="createHierLevNew">
                                    <xsl:with-param name="roleContent"
select="'ancestor'" />
        
<xsl:with-param name="newRole" select="$role"/>
        
<xsl:with-param name="marker" select="$markerValue"/>
        
</xsl:call-template>
                                               </xsl:with-param>
                        </xsl:call-template>
                                         </xsl:if>
                                         <xsl:if test=" $ancestorCount =
1 ">
                                                 <xsl:call-template
name="createHierLevNew">
                                    <xsl:with-param name="roleContent"
select="'ancestor'" />
        
<xsl:with-param name="newRole" select="$role"/>
        
<xsl:with-param name="marker" select="$markerValue"/>
        
</xsl:call-template>
                                         </xsl:if>
                                  </xsl:with-param>
          </xsl:call-template>
  </xsl:template>

  <xsl:template name="createHierLevNew">
    <xsl:param name="roleContent" />
        <xsl:param name="newRole" />
        <xsl:param name="marker"/>

        <xsl:call-template name="createHierLevElement">
        <xsl:with-param name="roleContent" select="$roleContent" />
        <xsl:with-param name="hierLevContent">
              <xsl:element name="heading">
             <xsl:element name="title">                 
                             <xsl:copy-of select="$marker"/>
             </xsl:element>
                </xsl:element>
                </xsl:with-param>
   </xsl:call-template>

    <xsl:call-template name="createHierLevElement">
        <xsl:with-param name="roleContent" select="$newRole" />
        <xsl:with-param name="hierLevContent">
              <xsl:element name="heading">
             <xsl:element name="title">                 
                             Infobase Title            
             </xsl:element>
                </xsl:element>
                </xsl:with-param>
   </xsl:call-template>
  </xsl:template> 

Tried to explain little better. If You have any questions about my
question, please let me know. So that I can explain in more detailed
manner.


-----Original Message-----
From: Michael Kay [mailto:mike(_at_)saxonica(_dot_)com] 
Sent: Tuesday, May 02, 2006 2:55 AM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: RE: [xsl] XSLT: Transforming one markup to another markup

It's a good idea not just to describe your objective, but also to
explain where your difficulty lies. It's difficult to answer a question
without knowing something of your level of understanding of the
language. There are some people on this list who might respond with a
complete worked solution, but most of us prefer, I think, to work out
where you're stuck, point you in the right direction, and then leave you
to solve the problem yourself. 

In this case, I'm afraid I can't reverse engineer the rules for the
transformation. You say:

2)In Y Markup--- always the last hierlev element contains two  hierlev

as children.

But that doesn't make sense. If the last hierlev element has two hierlev
children, then it's not the last hierlev element, because its children
come after it. 

Michael Kay
http://www.saxonica.com/



-----Original Message-----
From: Tedla, Sridhar (LNG-CSP) 
[mailto:Sridhar(_dot_)Tedla(_at_)lexisnexis(_dot_)com]
Sent: 02 May 2006 04:33
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT: Transforming one markup to another markup

Hi!
The X markup needs to be converted into Y markup.
The X markup is as follows:


<class scheme="SAT"> 
   <classitem> 
       <identifier> 
              <name>Sales </name> 
              <code>1234</code> 
       </identifier> 
       <classitem> 
         <identifier> 
                <name> Tax</name> 
                <code>5678</code> 
         </identifier> 
       <classitem> 
         <identifier> 
               <name>Items  </name> 
               <code>9101</code> 
         </identifier> 
        <classitem> 
           <identifier> 
              <name>Manufacturing </name> 
              <code>1121</code> 
           </identifier> 
           </classitem> 
      </classitem> 
     </classitem> 
    </classitem>
</class>

The Y Markup is has follows:

<hier>
  <hierlev role="ancestor">
     <heading>
      <title>Sales</title>
     </heading>

     <hierlev role="ancestor">
        <heading>
         <title> Tax</title>
         </heading>

         <hierlev role="ancestor">
      <heading>
              <title>Items </title>
      </heading>
            <hierlev role="ancestor">
             <heading>
                <title>Manufacturing </title>
             </heading>
                  <hierlev role="ancestor">
                 <heading>
                      <title>Revised Code </title>
                  </heading>
              </hierlev>
              <hierlev role="me">
                  <heading>
                      <title> Title Value</title>
                   </heading>
               </hierlev>
          </hierlev>
          </hierlev>
     </hierlev>
   </hierlev>
</hier>

Now two rules for the above conversion:
1)In X markup--The classitem depth is arbitary. 
2)In Y Markup--- always the last hierlev element contains two  hierlev

as children.


Sridhar


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



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

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