xlsx.xsl 9.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  12. exclude-result-prefixes="xs"
  13. version="2.0">
  14. <xsl:output indent="yes"/>
  15. <xsl:strip-space elements="*"/>
  16. <xsl:param name="Types__x3A__xlsx__x3A__unzipped_xlsx" required="yes"/> <!-- type dir there to unzipped dir of xlsx file -->
  17. <xsl:variable name="Types__x3A__xlsx:path">
  18. <!-- <xsl:for-each select="collection(iri-to-uri('../someDir/?select=[a-z][0-9]+.(xsl|xslt);recurse=yes'))"> -->
  19. <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>
  20. <xsl:value-of select=" iri-to-uri(concat($Types__x3A__xlsx__x3A__unzipped_xlsx,'?select=*.(xml|rels);recurse=yes;on-error=warning'))"/>
  21. </xsl:variable>
  22. <xsl:variable name="Types__x3A__xlsx:docs" select="collection($Types__x3A__xlsx:path)"/>
  23. <xsl:template name="Types__x3A__xlsx:main">
  24. <xsl:message>Executing Types__x3A__xlsx__x3A__main</xsl:message>
  25. <Types__x3A__xlsx:main>
  26. <xsl:for-each select="$Types__x3A__xlsx:docs">
  27. <xsl:apply-templates mode="Types__x3A__xlsx:sheets">
  28. <xsl:with-param name="document-uri" select="document-uri(/)"/>
  29. </xsl:apply-templates>
  30. </xsl:for-each>
  31. </Types__x3A__xlsx:main>
  32. </xsl:template>
  33. <xsl:template match="*">
  34. <xsl:message terminate="yes">ERROR this template should be called by call-template</xsl:message>
  35. </xsl:template>
  36. <xsl:template match="workbook" mode="Types__x3A__xlsx:sheets" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" >
  37. <xsl:param name="document-uri"/>
  38. <workbook>
  39. <xsl:attribute name="document-uri" select="$document-uri"/>
  40. <xsl:copy-of select="sheets"/>
  41. <!--<xsl:for-each select="sheets/sheet" > <!-\- xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" -\->
  42. <xsl:apply-templates mode="Types__x3A__xlsx:sheet" select="$Types__x3A__xlsx:docs">
  43. <xsl:with-param name="document-uri" select="$document-uri"/>
  44. <xsl:with-param name="name" select="@name"/>
  45. <xsl:with-param name="sheetId" select="@sheetId"/>
  46. <xsl:with-param name="r:id" select="@r:id"/>
  47. <xsl:with-param name="sheet_name" select="$sheet_names//sheet[@sheetId = current()/@sheetId]/@name"/>
  48. </xsl:apply-templates>
  49. </xsl:for-each>-->
  50. <!--<xsl:for-each select="sheets/sheet" >--> <!-- xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" -->
  51. <xsl:apply-templates mode="Types__x3A__xlsx:sheets" >
  52. <xsl:with-param name="document-uri" select="$document-uri"/>
  53. <xsl:with-param name="name" select="@name"/>
  54. <xsl:with-param name="sheetId" select="@sheetId"/>
  55. <xsl:with-param name="r:id" select="@r:id"/>
  56. <!--<xsl:with-param name="sheet_name" select="$sheet_names//sheet[@sheetId = current()/@sheetId]/@name"/>-->
  57. </xsl:apply-templates>
  58. <!--</xsl:for-each>-->
  59. </workbook>
  60. </xsl:template>
  61. <xsl:template match="*" mode="Types__x3A__xlsx:sheets Types__x3A__xlsx:sheet">
  62. <xsl:param name="document-uri"/>
  63. <!--<bypassed_86>
  64. <xsl:copy-of select="."/>
  65. </bypassed_86>-->
  66. <xsl:comment>#86 bypassed <xsl:value-of select="name()"/>
  67. <xsl:text>
  68. </xsl:text>
  69. <xsl:element name="{name()}">
  70. <xsl:copy-of select="@*"/>
  71. <name><xsl:value-of select="name()"/></name>
  72. <url><xsl:value-of select="$document-uri"/></url>
  73. </xsl:element>
  74. </xsl:comment>
  75. </xsl:template>
  76. <!--<xsl:template match="worksheet" mode="Types__x3A__xlsx:sheet">
  77. <xsl:param name="document-uri"/>
  78. <!-\-<bypassed_86>
  79. <xsl:copy-of select="."/>
  80. </bypassed_86>-\->
  81. <xsl:comment>#86 bypassed <xsl:value-of select="name()"/>
  82. <xsl:text>
  83. </xsl:text>
  84. <xsl:element name="{name()}">
  85. <xsl:copy-of select="@*"/>
  86. <name><xsl:value-of select="name()"/></name>
  87. <url><xsl:value-of select="$document-uri"/></url>
  88. </xsl:element>
  89. </xsl:comment>
  90. </xsl:template>-->
  91. <xsl:template match="worksheet" mode="Types__x3A__xlsx:sheets" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  92. <!--<xsl:param name="sheetId" required="yes"/>-->
  93. <xsl:param name="name"/>
  94. <xsl:param name="document-uri" select="document-uri(/)"/>
  95. <xsl:comment>#102 worksheet <xsl:value-of select="$document-uri"/>;</xsl:comment>
  96. <xsl:variable name="sheet_id" select="replace(replace(substring-after(document-uri(/),'/worksheets/'),'.xml',''),'sheet','')"/>
  97. <xsl:variable name="sheet_name" select="$Types__x3A__xlsx:docs/workbook/sheets/sheet[@sheetId = $sheet_id ]/@name" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main" />
  98. <!-- <xsl:choose>
  99. <xsl:when test=" substring-after( document-uri(/),'worksheets/')=concat('sheet',$sheetId,'.xml')">-->
  100. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData">
  101. <xsl:with-param name="sheet_name" select="$sheet_name"/>
  102. </xsl:apply-templates>
  103. <!-- </xsl:when>
  104. <xsl:otherwise>
  105. <xsl:comment>
  106. <inny_sheet><xsl:attribute name="sheetId_param" select="$sheetId"/>
  107. <xsl:value-of select="substring-after( document-uri(/),'worksheets/')"/>
  108. <test><xsl:value-of select="concat('sheet',$sheetId,'.xml')"/></test>
  109. </inny_sheet>
  110. </xsl:comment>
  111. </xsl:otherwise>
  112. </xsl:choose>-->
  113. </xsl:template>
  114. <xsl:template match="sheetData" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  115. <xsl:param name="sheet_name" required="yes"/>
  116. <sheetData>
  117. <xsl:attribute name="sheet_name" select="$sheet_name"/>
  118. <xsl:attribute name="document-uri" select="substring-after( document-uri(/),'worksheets/')"/>
  119. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData"/>
  120. </sheetData>
  121. </xsl:template>
  122. <xsl:template match="row" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  123. <row>
  124. <xsl:copy-of select="@r"/>
  125. <xsl:apply-templates mode="Types__x3A__xlsx:sheetData"/>
  126. </row>
  127. </xsl:template>
  128. <xsl:template match="c[@t='s']" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  129. <xsl:variable name="v" select="v/text()"/>
  130. <xsl:variable name="r" select="@r"/>
  131. <c><xsl:copy-of select="@*"/>
  132. <xsl:attribute name="v_deb_nr" select="$v"/>
  133. <xsl:attribute name="col" select=" replace(@r,'([0-9])','')"/>
  134. <v><xsl:value-of select="$Types__x3A__xlsx:docs/sst/si[position()=($v + 1)]/t" exclude-result-prefixes="#all"/></v>
  135. <!--<xsl:copy-of select="../../../hyperlinks/hyperlink"/>-->
  136. <xsl:apply-templates mode="Types__x3A__xlsx:Hyperlink" select="../../../hyperlinks/hyperlink[@ref=current()/@r]" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main"/>
  137. </c>
  138. </xsl:template>
  139. <xsl:template match="c" mode="Types__x3A__xlsx:sheetData" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  140. <xsl:variable name="r" select="@r"/>
  141. <c><xsl:copy-of select="@*"/>
  142. <xsl:attribute name="col" select=" replace(@r,'([0-9])','')"/>
  143. <v><xsl:copy-of select="v/text()" copy-namespaces="no"/></v>
  144. <xsl:apply-templates mode="Types__x3A__xlsx:Hyperlink" select="../../../hyperlinks/hyperlink[@ref=current()/@r]"/>
  145. </c>
  146. </xsl:template>
  147. <xsl:template match="hyperlink" mode="Types__x3A__xlsx:Hyperlink" xpath-default-namespace="http://schemas.openxmlformats.org/spreadsheetml/2006/main">
  148. <!--<xsl:value-of select="@r:id"/>-->
  149. <!--<xsl:copy-of select="$Types__x3A__xlsx:docs" xpath-default-namespace="http://schemas.openxmlformats.org/package/2006/relationships"/>-->
  150. <xsl:copy-of select="$Types__x3A__xlsx:docs/Relationships/Relationship[@Id=current()/@r:id]" xpath-default-namespace="http://schemas.openxmlformats.org/package/2006/relationships"/>
  151. </xsl:template>
  152. </xsl:stylesheet>