csv2xml.xsl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  3. xmlns:xs="http://www.w3.org/2001/XMLSchema"
  4. exclude-result-prefixes="xs"
  5. version="2.0">
  6. <xsl:param name="csv2xml" required="yes"/>
  7. <xsl:param name="input" required="yes"/>
  8. <xsl:param name="output" required="yes"/>
  9. <xsl:param name="basedir" required="yes"/>
  10. <xsl:output indent="yes"/>
  11. <xsl:strip-space elements="*"/>
  12. <xsl:template match="csv2xml_dir">
  13. <project basedir="{$basedir}" name="csv2xml_dir.child" default="csv2xml_dir.child.run">
  14. <target name="csv2xml_dir.child.run">
  15. <xsl:for-each select="tokenize(.,';')">
  16. <xsl:variable name="file" select="replace(.,' ','\\ ')"/>
  17. <xsl:variable name="file_out" select="replace(replace(.,' ','_'),'.csv','.xml')"/>
  18. <exec executable="bash" >
  19. <!--<env key="PATH" path="$PATH:${PATH_ADD}"/>-->
  20. <arg value="-c"/>
  21. <arg value="{$csv2xml} &lt; {$input}/{$file} &gt; {$output}/{$file_out}"/>
  22. </exec>
  23. </xsl:for-each>
  24. </target>
  25. </project>
  26. </xsl:template>
  27. <xsl:template match="any2xml_dir">
  28. <project basedir="{$basedir}" name="csv2xml_dir.child" default="csv2xml_dir.child.run">
  29. <target name="csv2xml_dir.child.run">
  30. <xsl:for-each select="tokenize(.,';')">
  31. <xsl:variable name="file" select="replace(.,' ',' ')"/>
  32. <xsl:variable name="file_out" select="concat(replace(.,' ','_'),'.xml')"/>
  33. <xsl:choose>
  34. <xsl:when test=" contains($file,'.xml')">
  35. <mkdir dir="{$output}/{$file_out}"/>
  36. <delete dir="{$output}/{$file_out}"/>
  37. <copy file="{$input}/{$file}" tofile="{$output}/{$file}"/>
  38. </xsl:when>
  39. <!--<xsl:when test="1 = 2"/>-->
  40. <xsl:otherwise>
  41. <loadfile property="{$file}" srcfile="{$input}/{$file}"/>
  42. <mkdir dir="{$output}/{$file_out}"/>
  43. <delete dir="{$output}/{$file_out}"/>
  44. <echoxml file="{$output}/{$file_out}" >
  45. <any2xml>
  46. ${<xsl:value-of select="$file"/>}
  47. </any2xml>
  48. </echoxml>
  49. </xsl:otherwise>
  50. </xsl:choose>
  51. </xsl:for-each>
  52. </target>
  53. </project>
  54. </xsl:template>
  55. </xsl:stylesheet>