title: Convert complex xml to csv using xsl using looping function
body: <p>I having a xml file here.. </p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  
  &lt;!DOCTYPE dependencies SYSTEM "http://depfind.sourceforge.net/dtd/dependencies.dtd"&gt;
  
  &lt;dependencies&gt;
      &lt;package confirmed="yes"&gt;
          &lt;name&gt;com.infopro.Dependency&lt;/name&gt;
          &lt;class confirmed="yes"&gt;
              &lt;name&gt;com.infopro.Dependency.A&lt;/name&gt;
              &lt;outbound type="class" confirmed="no"&gt;java.lang.Object&lt;/outbound&gt;
              &lt;outbound type="class" confirmed="no"&gt;javax.ejb.Stateless&lt;/outbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.B()&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.a&lt;/inbound&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.A()&lt;/name&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.b&lt;/outbound&gt;
                  &lt;outbound type="class" confirmed="yes"&gt;com.infopro.Dependency.B&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.B()&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="no"&gt;java.lang.Object.Object()&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.B()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.b&lt;/name&gt;
                  &lt;outbound type="class" confirmed="yes"&gt;com.infopro.Dependency.B&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.A()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.check(java.lang.String, java.lang.String)&lt;/name&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.stat&lt;/outbound&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.doStatus()&lt;/name&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.check(java.lang.String, java.lang.String)&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.name&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.user_id&lt;/outbound&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.name&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.stat&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.check(java.lang.String, java.lang.String)&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.A.user_id&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
          &lt;/class&gt;
          &lt;class confirmed="yes"&gt;
              &lt;name&gt;com.infopro.Dependency.B&lt;/name&gt;
              &lt;outbound type="class" confirmed="yes"&gt;com.infopro.Dependency.C&lt;/outbound&gt;
              &lt;outbound type="class" confirmed="no"&gt;java.lang.Object&lt;/outbound&gt;
              &lt;outbound type="class" confirmed="no"&gt;javax.ejb.Stateless&lt;/outbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.A()&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.b&lt;/inbound&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.B()&lt;/name&gt;
                  &lt;outbound type="class" confirmed="yes"&gt;com.infopro.Dependency.A&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.A()&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.a&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="no"&gt;java.lang.Object.Object()&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.A()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.a&lt;/name&gt;
                  &lt;outbound type="class" confirmed="yes"&gt;com.infopro.Dependency.A&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.B()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.check(java.lang.String, java.lang.String)&lt;/name&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.stat&lt;/outbound&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.doStatus()&lt;/name&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.check(java.lang.String, java.lang.String)&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.name&lt;/outbound&gt;
                  &lt;outbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.user_id&lt;/outbound&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.name&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.stat&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.check(java.lang.String, java.lang.String)&lt;/inbound&gt;
              &lt;/feature&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.B.user_id&lt;/name&gt;
                  &lt;outbound type="class" confirmed="no"&gt;java.lang.String&lt;/outbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.doStatus()&lt;/inbound&gt;
              &lt;/feature&gt;
          &lt;/class&gt;
          &lt;class confirmed="yes"&gt;
              &lt;name&gt;com.infopro.Dependency.C&lt;/name&gt;
              &lt;outbound type="class" confirmed="no"&gt;java.lang.Object&lt;/outbound&gt;
              &lt;outbound type="class" confirmed="no"&gt;javax.ejb.Remote&lt;/outbound&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.B&lt;/inbound&gt;
              &lt;feature confirmed="yes"&gt;
                  &lt;name&gt;com.infopro.Dependency.C.doStatus()&lt;/name&gt;
              &lt;/feature&gt;
          &lt;/class&gt;
      &lt;/package&gt;
      &lt;package confirmed="no"&gt;
          &lt;name&gt;java.lang&lt;/name&gt;
          &lt;class confirmed="no"&gt;
              &lt;name&gt;java.lang.Object&lt;/name&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.A&lt;/inbound&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.B&lt;/inbound&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.C&lt;/inbound&gt;
              &lt;feature confirmed="no"&gt;
                  &lt;name&gt;java.lang.Object.Object()&lt;/name&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.A()&lt;/inbound&gt;
                  &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.B()&lt;/inbound&gt;
              &lt;/feature&gt;
          &lt;/class&gt;
          &lt;class confirmed="no"&gt;
              &lt;name&gt;java.lang.String&lt;/name&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.check(java.lang.String, java.lang.String)&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.doStatus()&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.name&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.stat&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.A.user_id&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.check(java.lang.String, java.lang.String)&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.doStatus()&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.name&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.stat&lt;/inbound&gt;
              &lt;inbound type="feature" confirmed="yes"&gt;com.infopro.Dependency.B.user_id&lt;/inbound&gt;
          &lt;/class&gt;
      &lt;/package&gt;
      &lt;package confirmed="no"&gt;
          &lt;name&gt;javax.ejb&lt;/name&gt;
          &lt;class confirmed="no"&gt;
              &lt;name&gt;javax.ejb.Remote&lt;/name&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.C&lt;/inbound&gt;
          &lt;/class&gt;
          &lt;class confirmed="no"&gt;
              &lt;name&gt;javax.ejb.Stateless&lt;/name&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.A&lt;/inbound&gt;
              &lt;inbound type="class" confirmed="yes"&gt;com.infopro.Dependency.B&lt;/inbound&gt;
          &lt;/class&gt;
      &lt;/package&gt;
  &lt;/dependencies&gt;
  </code></pre>
  
  <p>I want to create a output of csv file in this format..</p>
  
  <pre><code>classname1, outbound.
  
  classname1, outbound.
  
  .             .
  
  .             .
  
  classname1, inbound.
  
  .             .
  
  .             .
  
  classname2, outbound.
  
  .             .
  
  classname2, inbound.
  </code></pre>
  
  <p>and so on..</p>
  
  <p>Now the challenge for me is the quantity of inbound and outbound for each class are different and varies. so i have to specify looping for that. And also i just need class name contains "com" keyword or string inside excluding package name, feature name all. I need do this xsl so that for all similiar xml i generate i can change it to csv table form for my further process of data that i needed.</p>
  
  <p>The xsl i created shown below but i stil facing some bugs and problems</p>
  
  <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt;
  
      &lt;xsl:output method="text"/&gt;
      &lt;xsl:strip-space elements="*"/&gt; 
  
  
      &lt;xsl:template match="class[contains(.//text(), 'com')]"&gt;
          &lt;xsl:text&gt;&lt;/xsl:text&gt;&lt;xsl:value-of select="name"/&gt;&lt;xsl:if test="@confirmed='no'"&gt; *&lt;/xsl:if&gt;&lt;xsl:text&gt; &lt;/xsl:text&gt;
          &lt;xsl:for-each select="outbound[contains(.//text(), 'com')]"&gt;
              &lt;xsl:text disable-output-escaping="yes"&gt;   , &lt;/xsl:text&gt;&lt;xsl:value-of select="."/&gt;&lt;xsl:if test="@confirmed='no'"&gt; *&lt;/xsl:if&gt;&lt;xsl:text&gt;
  &lt;/xsl:text&gt;
          &lt;/xsl:for-each&gt;
          &lt;xsl:for-each select="inbound[contains(.//text(), 'com')]"&gt;
              &lt;xsl:text disable-output-escaping="yes"&gt;   , &lt;/xsl:text&gt;&lt;xsl:value-of select="."/&gt;&lt;xsl:if test="@confirmed='no'"&gt; *&lt;/xsl:if&gt;&lt;xsl:text&gt;
  &lt;/xsl:text&gt;
          &lt;/xsl:for-each&gt;
      &lt;/xsl:template&gt;  
  &lt;/xsl:stylesheet&gt;
  </code></pre>
  
  <p>And the output as</p>
  
  <pre><code>com.infopro.Dependencycom.infopro.Dependency.A                               , com.infopro.Dependency.B.B()
                                                                               , com.infopro.Dependency.B.a
  com.infopro.Dependency.B                                                     , com.infopro.Dependency.C
                                                                               , com.infopro.Dependency.A.A()
                                                                               , com.infopro.Dependency.A.b
  com.infopro.Dependency.C                                                     , com.infopro.Dependency.B
  java.langjava.lang.Objectcom.infopro.Dependency.Acom.infopro.Dependency.Bcom.infopro.Dependency.Cjava.lang.Object.Object()com.infopro.Dependency.A.A()com.infopro.Dependency.B.B()java.lang.Stringcom.infopro.Dependency.A.check(java.lang.String, java.lang.String)com.infopro.Dependency.A.doStatus()com.infopro.Dependency.A.namecom.infopro.Dependency.A.statcom.infopro.Dependency.A.user_idcom.infopro.Dependency.B.check(java.lang.String, java.lang.String)com.infopro.Dependency.B.doStatus()com.infopro.Dependency.B.namecom.infopro.Dependency.B.statcom.infopro.Dependency.B.user_idjavax.ejbjavax.ejb.Remotecom.infopro.Dependency.Cjavax.ejb.Statelesscom.infopro.Dependency.Acom.infopro.Dependency.B
  </code></pre>
  
  <p>The table like arrangement almost occur but having problem with package name still coming stick with first class name, and some long string of unwanted java strings at the end.
  Hope for guidance and help. thank you</p>