response.xslt 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <!--
  3. This would be really nice to reduce the code-complexity of the (html) parser
  4. - if Apple wouldn't have chosen to consider libxslt a private API.
  5. http://stackoverflow.com/questions/7895157/applying-xslt-to-an-xml-coming-from-a-webservice-in-ios
  6. http://www.w3.org/TR/xslt
  7. Copyright (c) 2015-2016 Marcus Rohrmoser http://mro.name/me. All rights reserved.
  8. This program is free software: you can redistribute it and/or modify
  9. it under the terms of the GNU General Public License as published by
  10. the Free Software Foundation, either version 3 of the License, or
  11. (at your option) any later version.
  12. This program is distributed in the hope that it will be useful,
  13. but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. GNU General Public License for more details.
  16. You should have received a copy of the GNU General Public License
  17. along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. -->
  19. <xsl:stylesheet
  20. xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  21. exclude-result-prefixes="xsl"
  22. version="1.0">
  23. <xsl:output method="xml" indent="yes"/>
  24. <xsl:template match="/">
  25. <shaarli>
  26. <!-- naked error message -->
  27. <xsl:for-each select="/html[1 = count(*)]/head[1 = count(*)]/script[starts-with(.,'alert(')]">
  28. <error message="{normalize-space(substring-before(substring-after(.,'alert(&quot;'), '&quot;'))}"/>
  29. </xsl:for-each>
  30. <xsl:for-each select="/html/body">
  31. <!-- embedded error message -->
  32. <xsl:for-each select="div[@id = 'pageheader']/div[@id='headerform' and 0 = count(*)]">
  33. <error message="{normalize-space(.)}"/>
  34. </xsl:for-each>
  35. <!-- shaarli title -->
  36. <xsl:for-each select="//span[@id = 'shaarli_title']">
  37. <xsl:attribute name="title">
  38. <xsl:value-of select="normalize-space(.)"/>
  39. </xsl:attribute>
  40. </xsl:for-each>
  41. <!-- logged in? -->
  42. <is_logged_in value="{1 = count(div[@id = 'pageheader']//a[@href = '?do=logout'])}"/>
  43. <!-- xsl:choose>
  44. <xsl:when test="1 = count(div[@id = 'pageheader']//a[@href = '?do=logout'])">
  45. </xsl:when>
  46. <xsl:otherwise>
  47. <is_logged_in value="false"/>
  48. </xsl:otherwise>
  49. </xsl:choose -->
  50. <!-- login and link form field presets and TOKEN -->
  51. <xsl:for-each select="//form[@name='loginform' or @name='linkform']">
  52. <xsl:copy>
  53. <xsl:for-each select="@* | .//input">
  54. <xsl:copy-of select="."/>
  55. </xsl:for-each>
  56. </xsl:copy>
  57. </xsl:for-each>
  58. <!-- tags from tagcloud (unused) -->
  59. <xsl:for-each select="//div[@id = 'cloudtag']/span[@class = 'count']">
  60. <tag count="{.}">
  61. <xsl:for-each select="following-sibling::a[1]">
  62. <xsl:attribute name="href">
  63. <xsl:value-of select="@href"/>
  64. </xsl:attribute>
  65. <xsl:attribute name="title">
  66. <xsl:value-of select="normalize-space(.)"/>
  67. </xsl:attribute>
  68. </xsl:for-each>
  69. </tag>
  70. </xsl:for-each>
  71. </xsl:for-each>
  72. </shaarli>
  73. </xsl:template>
  74. </xsl:stylesheet>