Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on May 16th, 2012  |  syntax: None  |  size: 9.45 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. My XML look like this......
  2.  
  3. <?xml version="1.0" encoding="UTF-8"?>
  4. <dataroot xmlns:od="urn:schemas-
  5.     microsoft-com:officedata" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  xsi:noNamespaceSchemaLocation="test.xsd" generated="2010-08-20T01:52:04">
  6.     <BU>
  7.         <Classification1>Air Cargo</Classification1>
  8.         <Customer>Freight International LLC</Customer>
  9.         <City>parco</City>
  10.         <Box>11745</Box>
  11.         <TelCode>04</TelCode>
  12.         <TelNo>3430060</TelNo>
  13.         <FaxNo>3430075</FaxNo>
  14.         <priority1>#</priority1>
  15.         <Image>aaa.ai</Image>
  16.     </BU>
  17.     <BU>
  18.         <Classification1>Air Cargo</Classification1>
  19.         <Customer>Freight International LLC</Customer>
  20.         <City>tazese</City>
  21.         <Box>11745</Box>
  22.         <TelCode>09</TelCode>
  23.         <TelNo>3431234</TelNo>
  24.         <FaxNo>3434321</FaxNo>
  25.         <priority1>#</priority1>
  26.         <Image>aaa.ai</Image>
  27.     </BU>
  28.     <BU>
  29.         <Classification1>Air Cargo</Classification1>
  30.         <Customer>Freight International LLC</Customer>
  31.         <City>raseus</City>
  32.         <Box>56899</Box>
  33.         <TelCode>08</TelCode>
  34.         <TelNo>347890</TelNo>
  35.         <FaxNo>345678</FaxNo>
  36.         <priority1>#</priority1>
  37.         <Image>aassa.ai</Image>
  38.     </BU>
  39.     <BU>
  40.         <Classification1>Air Cargo</Classification1>
  41.         <Customer>ooohs International LLC</Customer>
  42.         <City>uiiri</City>
  43.         <Box>53499</Box>
  44.         <TelCode>06</TelCode>
  45.         <TelNo>347990</TelNo>
  46.         <FaxNo>340988</FaxNo>
  47.         <priority2>%</priority2>
  48.         <Image>aaa.ai</Image>
  49.     </BU>
  50.     <BU>
  51.         <Classification1>Air Cargo</Classification1>
  52.         <Customer>kas International LLC</Customer>
  53.         <City>kiriri</City>
  54.         <Box>533699</Box>
  55.         <TelCode>06</TelCode>
  56.         <TelNo>347890</TelNo>
  57.         <FaxNo>342588</FaxNo>
  58.         <priority3>^</priority3>
  59.         <Image>aaa.ai</Image>
  60.     </BU>
  61.     <BU>
  62.         <Classification1>Air Cargo</Classification1>
  63.         <Customer>kas International LLC</Customer>
  64.         <City>kiriri</City>
  65.         <Box>533699</Box>
  66.         <TelCode>06</TelCode>
  67.         <TelNo>347890</TelNo>
  68.         <FaxNo>342588</FaxNo>
  69.         <priority3>^</priority3>
  70.         <Image>aaa.ai</Image>
  71.     </BU>
  72. </dataroot>
  73.  
  74.  
  75. My XSLT look like this......
  76.  
  77.  
  78. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  79. <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp ""> ]>
  80. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
  81.     <xsl:param name="platform">win</xsl:param>
  82.     <xsl:param name="sortbylang">en-us</xsl:param>
  83.     <xsl:output indent="no" encoding="UTF-8" method="xml"/>
  84.     <xsl:strip-space elements="*"/>
  85.     <xsl:template match="/">
  86.         <xsl:variable name="blocks" select="dataroot/BU"/>
  87.         <xsl:variable name="images" select="dataroot/BU/Image"/>
  88.         <xsl:variable name="customers" select="dataroot/BU/Customer"/>
  89.              
  90.         <Root>
  91.             <xsl:result-document method="xml" href="alpha_out1.xml">
  92.                <xsl:for-each-group select="dataroot/BU" group-by="substring(Customer,1,1)">
  93.                     <xsl:sort select="current-grouping-key()" order="ascending"/>
  94.                    
  95.                     <xsl:variable name="currentGroup"><xsl:value-of select="current-grouping-key()"/></xsl:variable>
  96.                     <xsl:for-each select=".">
  97.                         <xsl:element name="title">
  98.                             <xsl:value-of select="current-grouping-key()"/>
  99.                            
  100.                         </xsl:element><xsl:text>&#xA;</xsl:text>
  101.                          <xsl:for-each select="current-group()">
  102.                             <!-- new sorting --> <xsl:sort  select="Customer" order="ascending"/>
  103.                            
  104.                             <xsl:apply-templates/>
  105.                         </xsl:for-each>
  106.                        </xsl:for-each>        
  107.                 </xsl:for-each-group>
  108.                 </xsl:result-document>
  109.         </Root>
  110.     </xsl:template>
  111.  
  112.     <xsl:template match="Customer">
  113.        
  114.         <xsl:if test="following-sibling::Image"><xsl:apply-templates select="following-sibling::Image" mode="siblingImage"/></xsl:if>
  115.         <Customer>
  116.             <xsl:value-of select="."/>
  117.             <xsl:text></xsl:text>
  118.         </Customer>
  119.        
  120.         <xsl:text>&#xA;</xsl:text>
  121.         <xsl:if test="following-sibling::Box | following-sibling::City | following-sibling::TelCode | following-sibling::TelNo">
  122.             <Address>
  123.                 <xsl:if test="string-length(following-sibling::Box) &gt; 1">Box <xsl:value-of select="following-sibling::Box"/>
  124.                     <xsl:text>, </xsl:text></xsl:if>
  125.                 <xsl:if test="string-length(following-sibling::City) &gt; 1"><xsl:value-of select="following-sibling::City"/>
  126.                     <xsl:text>, </xsl:text></xsl:if>
  127.                
  128.                 <xsl:if test="string-length(following-sibling::TelNo) &gt; 1"><xsl:text>&#9;</xsl:text>
  129.                     <xsl:if test="string-length(following-sibling::TelCode) &gt; 1">
  130.                         <xsl:value-of select="following-sibling::TelCode"/><xsl:text> </xsl:text></xsl:if>
  131.                     <xsl:value-of select="following-sibling::TelNo"/></xsl:if>
  132.             </Address>
  133.             <xsl:text></xsl:text>
  134.         </xsl:if>
  135.    
  136.         <xsl:text>&#xA;</xsl:text>
  137.        
  138.     </xsl:template>
  139.    
  140.    
  141.     <!-- make an href value for Image element -->
  142.     <xsl:template match="Image" mode="siblingImage">
  143.         <!-- make the href value into a variable value -->
  144.         <xsl:variable name="image">
  145.             <xsl:value-of select="@href"/>
  146.         </xsl:variable>
  147.         <!-- get the image name <Image href="images\blue logo.eps"/> -->
  148.         <xsl:variable name="imageFolder">
  149.             <xsl:value-of select="substring-before($image,'\')"/>
  150.         </xsl:variable>
  151.         <xsl:variable name="imageHref">
  152.             <xsl:value-of select="substring-after($image,'\')"/>
  153.         </xsl:variable>
  154.         <xsl:element name="Image">
  155.             <xsl:choose>
  156.                 <xsl:when test="$platform='win'">
  157.                     <!-- change any space to %20 -->
  158.                     <xsl:variable name="winImage">
  159.                         <xsl:value-of select="translate($imageHref,' ','%20')"/>
  160.                     </xsl:variable>
  161.                     <!-- build the Windows file path -->
  162.                     <xsl:variable name="winPath">
  163.                         <xsl:text>file:///D:/new%20dicrectory/Alpha%20New/images/</xsl:text>
  164.                         <xsl:value-of select="."/>
  165.                        
  166.                     </xsl:variable>
  167.                     <!-- put the windows path to the image into the href attribute value -->
  168.                     <xsl:attribute name="href">
  169.                         <xsl:value-of select="$winPath"/>
  170.                     </xsl:attribute>
  171.                 </xsl:when>
  172.                 <xsl:when test="$platform='mac'">
  173.                     <xsl:attribute name="href">
  174.                         <!-- not sure how to handle the mac path so will just copy it for now -->
  175.                         <xsl:value-of select="$image"/>
  176.                     </xsl:attribute>
  177.                 </xsl:when>
  178.             </xsl:choose>
  179.            
  180.         </xsl:element>
  181.         <xsl:text>&#xA;</xsl:text>
  182.     </xsl:template>
  183.      
  184.     <xsl:template match="*|@*"/>
  185. </xsl:stylesheet>
  186.  
  187.  
  188. My Result look like this.............
  189.  
  190. <?xml version="1.0" encoding="UTF-8"?>
  191. <title>F</title>
  192. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  193. <Customer>Freight International LLC</Customer>
  194. <Address>Box 11745, parco,     04 3430060</Address>
  195. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  196. <Customer>Freight International LLC</Customer>
  197. <Address>Box 11745, tazese,     09 3431234</Address>
  198. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aassa.ai"/>
  199. <Customer>Freight International LLC</Customer>
  200. <Address>Box 56899, raseus,     08 347890</Address>
  201. <title>k</title>
  202. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  203. <Customer>kas International LLC</Customer>
  204. <Address>Box 533699, kiriri,     06 347890</Address>
  205. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  206. <Customer>kas International LLC</Customer>
  207. <Address>Box 533699, kiriri,     06 347890</Address>
  208. <title>o</title>
  209. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  210. <Customer>ooohs International LLC</Customer>
  211. <Address>Box 53499, uiiri,     06 347990</Address>
  212.  
  213. I want final result look like this....
  214.  
  215. <?xml version="1.0" encoding="UTF-8"?>
  216. <Root>
  217. <title>F</title>
  218. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  219. <Customer>Freight International LLC</Customer>
  220. <Address>Box 11745, parco,     04 3430060</Address>
  221. <Address>Box 11745, tazese,     09 3431234</Address>
  222. <Address>Box 56899, raseus,     08 347890</Address>
  223. <title>k</title>
  224. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  225. <Customer>kas International LLC</Customer>
  226. <Address>Box 533699, kiriri,     06 347890</Address>
  227. <title>o</title>
  228. <Image href="file:///D:/new%20dicrectory/Alpha%20New/images/aaa.ai"/>
  229. <Customer>ooohs International LLC</Customer>
  230. <Address>Box 53499, uiiri,     06 347990</Address>
  231. </Root>
  232.  
  233. One Customer having few branches so braches should come under the customer, Same time i want remove duplicate XML data(Maybe same data come repeat)