qrcode.style.xsl 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!-- XSLT style for the XML output example -->
  3. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  4. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  5. <xsl:template match="/">
  6. <!-- SVG header -->
  7. <svg xmlns="http://www.w3.org/2000/svg"
  8. version="1.0"
  9. viewBox="0 0 {qrcode/matrix/@width} {qrcode/matrix/@height}"
  10. preserveAspectRatio="xMidYMid"
  11. >
  12. <!--
  13. path for a single module
  14. we could define a path for each layer and use the @layer attribute for selection,
  15. but that would exaggerate this example
  16. -->
  17. <symbol id="module" width="1" height="1">
  18. <circle cx="0.5" cy="0.5" r="0.4" />
  19. </symbol>
  20. <!-- loop over the rows -->
  21. <xsl:for-each select="qrcode/matrix/row">
  22. <!-- set a variable for $y (vertical) -->
  23. <xsl:variable name="y" select="@y"/>
  24. <xsl:for-each select="module">
  25. <!-- set a variable for $x (horizontal) -->
  26. <xsl:variable name="x" select="@x"/>
  27. <!-- draw only dark modules -->
  28. <xsl:if test="@dark='true'">
  29. <!-- position the module and set its fill color -->
  30. <use href="#module" class="{@layer}" x="{$x}" y="{$y}" fill="{@value}"/>
  31. </xsl:if>
  32. </xsl:for-each>
  33. </xsl:for-each>
  34. </svg>
  35. </xsl:template>
  36. </xsl:stylesheet>