xlsx.xsl 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  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. xmlns:Types__x3A__xlsx="https://biuro.biall-net.pl/wfs/default_db/Types/xlsx.xsd"
  5. xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships"
  6. xmlns:cp="http://schemas.openxmlformats.org/package/2006/metadata/core-properties"
  7. xmlns:dc="http://purl.org/dc/elements/1.1/"
  8. xmlns:dcterms="http://purl.org/dc/terms/"
  9. xmlns:dcmitype="http://purl.org/dc/dcmitype/"
  10. xmlns:a="http://schemas.openxmlformats.org/drawingml/2006/main"
  11. exclude-result-prefixes="xs"
  12. version="2.0">
  13. <xsl:output indent="yes"/>
  14. <xsl:strip-space elements="*"/>
  15. <xsl:param name="Types__x3A__xlsx__x3A__unzipped_xlsx" required="yes"/> <!-- type dir there to unzipped dir of xlsx file -->
  16. <xsl:variable name="Types__x3A__xlsx:path">
  17. <!-- <xsl:for-each select="collection(iri-to-uri('../someDir/?select=[a-z][0-9]+.(xsl|xslt);recurse=yes'))"> -->
  18. <xsl:message> Looking for xml doc files at <xsl:value-of select=" iri-to-uri(concat($Types__x3A__xlsx__x3A__unzipped_xlsx,'?select=*.(xml|rels);recurse=yes;on-error=warning'))"/></xsl:message>
  19. <xsl:value-of select=" iri-to-uri(concat($Types__x3A__xlsx__x3A__unzipped_xlsx,'?select=*.(xml|rels);recurse=yes;on-error=warning'))"/>
  20. </xsl:variable>
  21. <xsl:variable name="Types__x3A__xlsx:docs" select="collection($Types__x3A__xlsx:path)"/>
  22. <xsl:template name="Types__x3A__xlsx:main">
  23. <xsl:message>Executing Types__x3A__xlsx__x3A__main</xsl:message>
  24. <Types__x3A__xlsx:main>
  25. <xsl:for-each select="$Types__x3A__xlsx:docs">
  26. <xsl:apply-templates mode="Types__x3A__xlsx:sheets">
  27. <xsl:with-param name="document-uri" select="document-uri(/)"/>
  28. </xsl:apply-templates>
  29. </xsl:for-each>
  30. </Types__x3A__xlsx:main>
  31. </xsl:template>
  32. <xsl:template match="*">
  33. <xsl:message terminate="yes">ERROR this template should be called by call-template</xsl:message>
  34. </xsl:template>
  35. <xsl:template match="workbook" mode="Types__x3A__xlsx:sheets" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" >
  36. <xsl:param name="document-uri"/>
  37. <workbook>
  38. <xsl:for-each select="sheets/sheet" > <!-- xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" -->
  39. <xsl:apply-templates mode="Types__x3A__xlsx:sheet" select="$Types__x3A__xlsx:docs">
  40. <xsl:with-param name="name" select="@name"/>
  41. <xsl:with-param name="sheetId" select="@sheetId"/>
  42. <xsl:with-param name="r:id" select="@r:id"/>
  43. </xsl:apply-templates>
  44. </xsl:for-each>
  45. </workbook>
  46. </xsl:template>
  47. <xsl:template match="*" mode="Types__x3A__xlsx:sheets Types__x3A__xlsx:sheet">
  48. <xsl:param name="document-uri"/>
  49. <xsl:element name="{name()}">
  50. <xsl:copy-of select="@*"/>
  51. <name><xsl:value-of select="name()"/></name>
  52. <url><xsl:value-of select="$document-uri"/></url>
  53. </xsl:element>
  54. </xsl:template>
  55. <xsl:template match="worksheet" mode="Types__x3A__xlsx:sheet" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  56. <xsl:param name="sheetId" required="yes"/>
  57. <xsl:param name="name"/>
  58. <xsl:choose>
  59. <xsl:when test=" substring-after( document-uri(/),'worksheets/')=concat('sheet',$sheetId,'.xml')">
  60. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData"/>
  61. </xsl:when>
  62. <xsl:otherwise>
  63. <inny_sheet><xsl:attribute name="sheetId_param" select="$sheetId"/>
  64. <xsl:value-of select="substring-after( document-uri(/),'worksheets/')"/>
  65. <test><xsl:value-of select="concat('sheet',$sheetId,'.xml')"/></test>
  66. </inny_sheet>
  67. </xsl:otherwise>
  68. </xsl:choose>
  69. </xsl:template>
  70. <xsl:template match="sheetData" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  71. <sheetData>
  72. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData"/>
  73. </sheetData>
  74. </xsl:template>
  75. <xsl:template match="row" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  76. <row>
  77. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData"/>
  78. </row>
  79. </xsl:template>
  80. <xsl:template match="c[@t='s']" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  81. <xsl:variable name="v" select="v/text()"/>
  82. <xsl:variable name="r" select="@r"/>
  83. <c><xsl:copy-of select="@*"/><xsl:attribute name="v_deb_nr" select="$v"/>
  84. <v><xsl:value-of select="$Types__x3A__xlsx:docs/sst/si[position()=$v]/t" exclude-result-prefixes="#all"/></v>
  85. <!--<xsl:copy-of select="../../../hyperlinks/hyperlink"/>-->
  86. <xsl:apply-templates mode="Types__x3A__xlsx:Hyperlink" select="../../../hyperlinks/hyperlink[@ref=current()/@r]" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
  87. </c>
  88. </xsl:template>
  89. <xsl:template match="c" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  90. <xsl:variable name="r" select="@r"/>
  91. <c><xsl:copy-of select="@*"/>
  92. <v><xsl:copy-of select="v/text()" copy-namespaces="no"/></v>
  93. <xsl:apply-templates mode="Types__x3A__xlsx:Hyperlink" select="../../../hyperlinks/hyperlink[@ref=current()/@r]"/>
  94. </c>
  95. </xsl:template>
  96. <xsl:template match="hyperlink" mode="Types__x3A__xlsx:Hyperlink" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  97. <!--<xsl:value-of select="@r:id"/>-->
  98. <!--<xsl:copy-of select="$Types__x3A__xlsx:docs" xpath-default-namespace="http://schemas.openxmlformats.org/package/2006/relationships"/>-->
  99. <xsl:copy-of select="$Types__x3A__xlsx:docs/Relationships/Relationship[@Id=current()/@r:id]" xpath-default-namespace="http://schemas.openxmlformats.org/package/2006/relationships"/>
  100. </xsl:template>
  101. </xsl:stylesheet>