source: archiver/pipelines/actions/mediatypes/css.xpl @ 01a6690

Revision 01a6690, 4.2 KB checked in by Eric van der Vlist <vdv@dyomedea.com>, 14 months ago (diff)

First version that can produce a packaged archive.

  • Property mode set to 100644
Line 
1<p:config xmlns:p="http://www.orbeon.com/oxf/pipeline" xmlns:oxf="http://www.orbeon.com/oxf/processors" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:saxon="http://saxon.sf.net/">
2
3  <p:param name="archive" type="input"/>
4  <p:param name="rewritten" type="output"/>
5  <p:param name="links" type="output"/>
6
7
8  <!-- Store the document -->
9  <p:processor name="oxf:file-serializer">
10    <p:input name="config">
11      <config>
12        <scope>session</scope>
13      </config>
14    </p:input>
15    <p:input name="data" href="#archive#xpointer(/archive/response/document)"/>
16    <p:output name="data" id="url-written"/>
17  </p:processor>
18
19  <!-- And read it as CSS -->
20  <p:processor name="oxf:url-generator">
21    <p:input name="config" transform="oxf:xslt" href="#url-written">
22      <config xsl:version="2.0">
23        <url>
24          <xsl:value-of select="/*"/>
25        </url>
26        <content-type>text/css</content-type>
27        <mode>text</mode>
28      </config>
29    </p:input>
30    <p:output name="data" id="css" debug="css"/>
31  </p:processor>
32
33  <!-- Get a list of links to update -->
34  <!-- TODO: support links in inline CSS -->
35  <!-- TODO: support iframes and objects -->
36  <p:processor name="oxf:unsafe-xslt">
37    <p:input name="data" href="#css"/>
38    <p:input name="request" href="#archive#xpointer(/archive/request)"/>
39    <p:input name="config">
40      <xsl:stylesheet version="2.0">
41        <xsl:variable name="base" select="doc('input:request')/request/location"/>
42        <xsl:template match="/">
43          <links>
44            <xsl:variable name="links" as="node()*">
45              <xsl:analyze-string select="document" regex="url\([&quot;']?([^)'&quot;]+)[&quot;']?\)" flags="">
46                <xsl:matching-substring>
47                  <link href="{regex-group(1)}"/>
48                </xsl:matching-substring>
49              </xsl:analyze-string>
50            </xsl:variable>
51            <xsl:for-each-group select="$links" group-by="@href">
52              <xsl:variable name="abs-href" select="resolve-uri(@href, $base)"/>
53              <xsl:variable name="tokens" select="tokenize($abs-href, '/')"/>
54              <xsl:variable name="last-token" select="$tokens[last()]"/>
55              <xsl:variable name="tokens2" select="tokenize($last-token, '\.')"/>
56              <xsl:variable name="extension" select="$tokens2[last()]"/>
57              <link abs-href="{$abs-href}" new-href="{saxon:string-to-hexBinary(substring($abs-href, 1, string-length($abs-href) - string-length($extension) - 1), 'utf-8')}.{$extension}"
58                filename="{saxon:string-to-hexBinary($abs-href, 'utf-8')}.xml">
59                <xsl:copy-of select="@*"/>
60              </link>
61            </xsl:for-each-group>
62          </links>
63        </xsl:template>
64      </xsl:stylesheet>
65    </p:input>
66    <p:output name="data" id="links-local" debug="links"/>
67  </p:processor>
68
69  <p:processor name="oxf:identity">
70    <p:input name="data" href="#links-local"/>
71    <p:output name="data" ref="links"/>
72  </p:processor>
73
74  <!-- Update the links -->
75  <p:processor name="oxf:unsafe-xslt">
76    <p:input name="data" href="#css"/>
77    <p:input name="request" href="#archive#xpointer(/archive/request)"/>
78    <p:input name="links" href="#links-local"/>
79    <p:input name="config">
80      <xsl:stylesheet version="2.0">
81        <xsl:variable name="links" select="doc('input:links')/links"/>
82        <xsl:variable name="base" select="doc('input:request')/request/location"/>
83        <xsl:key name="link" match="link" use="@href"/>
84        <xsl:template match="/document">
85          <xsl:copy>
86            <xsl:copy-of select="@*"/>
87            <xsl:analyze-string select="." regex="url\([&quot;']?([^)'&quot;]+)[&quot;']?\)" flags="">
88              <xsl:matching-substring>
89                <xsl:text>url(</xsl:text>
90                <xsl:value-of select="$links/key('link', regex-group(1))/@new-href"/>
91                <xsl:text>)</xsl:text>
92              </xsl:matching-substring>
93              <xsl:non-matching-substring>
94                <xsl:copy-of select="."/>
95              </xsl:non-matching-substring>
96            </xsl:analyze-string>
97          </xsl:copy>
98        </xsl:template>
99      </xsl:stylesheet>
100    </p:input>
101    <p:output name="data" ref="rewritten" debug="rewritten"/>
102  </p:processor>
103
104 
105
106</p:config>
Note: See TracBrowser for help on using the repository browser.