xsl-list
[Top] [All Lists]

RE: [xsl] Converting an xml to another xml Using XSLT

2006-05-02 11:58:30
I got an e-mail suggesting that my subject line has an "Uninformative
Subject Line" and the code should be small. That's why I made lot of
modification. Sorry for the confusion.



-----Original Message-----
From: Jon Gorman [mailto:jonathan(_dot_)gorman(_at_)gmail(_dot_)com] 
Sent: Tuesday, May 02, 2006 12:52 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] Converting an xml to another xml Using XSLT

On 5/2/06, Tedla, Sridhar (LNG-CSP) 
<Sridhar(_dot_)Tedla(_at_)lexisnexis(_dot_)com>
wrote:
Question: Converting an XML markup to another XML Markup Using XSLT.

Sample XML Markup:
<class >
   <classitem>
     <identifier>
        <name>Sales </name>
               <code>1234</code>
     </identifier>
     <classitem>
        <identifier>
          <name> Tax</name>
          <code>5678</code>
       </identifier>
     </classitem>
    </classitem>
</class>

After XSL Transformation, the output markup should be as follows:
  <hier>
          <hierlev >
             <heading>
                <title>Sales</title>
             </heading>
             <hierlev>
                <heading>
                    <title> Tax</title>
                </heading>
               </hierlev>
            </hierlev>
    </hier>

The mapping between Input and output markup elements as follows:

class  -     hier
Classitem - heirlev
identifier -  heading
name       - title
code has no mapping i.e. the element can be ignored in XSLT Code

I have written XSLT code which works for fixed depth of class.Actually

I have written XSLT code for classItem depth of 4, but for
simplicity...
the following code is for classItem depth of 2 only.
<xsl:template match="class">
        <xsl:param name="count"/>
        <xsl:param name="v1" select="descendant::name[1]/text()"/>
        <xsl:param name="v2" select="descendant::name[2]/text()"/>
        <xsl:call-template name="createHierLevElement">
          <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=" $count = 2 ">
                  <xsl:call-template name="createHierLevElement">
                      <xsl:with-param name="hierLevContent">
                          <xsl:element name="heading">
                             <xsl:element name="title">
                                  <xsl:copy-of select="$v2"/>
                             </xsl:element>
                          </xsl:element>
                       </xsl:with-param>
                   </xsl:call-template>
                </xsl:if>
             </xsl:with-param>
        </xsl:call-template>
  </xsl:template>


  <xsl:template name="createHierLevElement">
      <xsl:param name="hierLevContent" />

        <xsl:element name="hierlev">
           <xsl:copy-of select="$hierLevContent" />
        </xsl:element>
    </xsl:template>


This doesn't quite look like the other examples you've already posted.
 (Also, try to stick with the same thread, it can get confusing for some
of us if you jump around)>

I'm finding myself confused as to why you're doing all of this...it
would seem you could simply do:

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

<xsl:template match="classitem">
<hierlev>
<heading>
   <title><xsl:value-of select="name" /></title> </heading>
<xsl:apply-templates /> </hierlev> </xsl:template>

One of the strengths of XSLT is how it will travel down the length of
the entire tree.

Is the problem more complicated than this?  (Perhaps it is, I don't have
time to flip back a couple of of threads to find out)

Jon Gorman

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