|
1 | 1 | * Saxon XInclude Processor |
2 | 2 | :PROPERTIES: |
3 | | -:CUSTOM_ID: h-A2085245-5C37-47C0-A798-B9BA74A7E5DD |
| 3 | +:CUSTOM_ID: h-CE868C20-B294-4E6F-A808-71029DFE0E4B |
4 | 4 | :END: |
5 | 5 |
|
6 | | -This is an [[http://www.w3.org/TR/xinclude][XInclude]] processor. It operates on the Saxon data model; it |
7 | | -is not a streaming processor. |
8 | | - |
9 | | -At the Java level, it works like this: |
10 | | - |
11 | | -#+BEGIN_SRC java |
12 | | -XdmNode document = … // You got a document from somewhere, right? |
13 | | -XInclude xinclude = new XInclude(); |
14 | | -XdmNode expanded = xinclude.expandXIncludes(document); |
15 | | -#+END_SRC |
16 | | - |
17 | | -It supports the ~xmlns~, ~element~, ~text~, ~xpath~, and ~search~ fragment |
18 | | -identifier schemes. |
19 | | - |
20 | | -I tried to build it in an extensible, pluggable way so that new |
21 | | -schemes could be added with relative ease, but that may be a bit |
22 | | -aspirational. |
23 | | - |
24 | | -* Extension function |
25 | | -:PROPERTIES: |
26 | | -:CUSTOM_ID: h-9CC4637B-261F-45DB-8F6B-241DC0E722AF |
27 | | -:END: |
28 | | - |
29 | | -You can use this XInclude implementation from XSLT as an extension |
30 | | -function. Pass the command line option ~-init:com.nwalsh.xslt.Register~ |
31 | | -to Saxon to register the extension function. (If you’re running Saxon |
32 | | -in some other context, arrange to have the function registered). |
33 | | - |
34 | | -In your stylesheet, declare the extension namespace: |
35 | | - |
36 | | -#+BEGIN_SRC xml |
37 | | -<?xml version="1.0" encoding="utf-8"?> |
38 | | -<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" |
39 | | - |
40 | | - xmlns:ext="http://nwalsh.com/xslt" |
41 | | - |
42 | | - xmlns:xs="http://www.w3.org/2001/XMLSchema" |
43 | | - exclude-result-prefixes="ext xs" |
44 | | - version="3.0"> |
45 | | -#+END_SRC |
46 | | - |
47 | | -Then you can call the extension function: |
48 | | - |
49 | | -#+BEGIN_SRC xml |
50 | | -<xsl:sequence select="ext:xinclude($node, $options)"/> |
51 | | -#+END_SRC |
52 | | - |
53 | | -You can use ~function-available()~ to code more defensively. The options |
54 | | -map is a map from QName keys to values. Only two keys are recognized: |
55 | | -~fixup-xml-base~ and ~fixup-xml-lang~, both in no namespace. The default |
56 | | -value for each is “true”. You can omit the second argument entirely if |
57 | | -you’re happy with those defaults. |
58 | | - |
59 | | -** Command line example |
60 | | -:PROPERTIES: |
61 | | -:CUSTOM_ID: h-38B19AEE-42B0-4828-A637-5E146C8334D7 |
62 | | -:END: |
63 | | - |
64 | | -You can use the ~xinclude.xsl~ file included in the distribution to |
65 | | -expand the XIncludes in a document. |
66 | | - |
67 | | -The trickiest part, as usual with Java applications, is arranging for |
68 | | -the correct classpath. You need to include the Saxon jar file, the |
69 | | -SInclude jar file, and any other jars that are necessary for |
70 | | -dependencies (for example, the XML Resolver jar files for Saxon 11+). |
71 | | - |
72 | | -If you have downloaded Saxon HE 11.5 and unzipped it into the |
73 | | -directory ~saxon~, the following classpath will work: |
74 | | - |
75 | | -#+BEGIN_SRC |
76 | | -export CLASSPATH=saxon/saxon-he-11.5.jar\ |
77 | | -:saxon/lib/xmlresolver-4.6.4.jar\ |
78 | | -:build/libs/sinclude-4.2.1.jar |
79 | | -#+END_SRC |
80 | | - |
81 | | -On Windows, the syntax is different. And you may find it more |
82 | | -convienent to run from a shell script. The actual transformation is: |
83 | | - |
84 | | -#+BEGIN_SRC |
85 | | -java -cp $CLASSPATH net.sf.saxon.Transform \ |
86 | | - -init:com.nwalsh.xslt.Register \ |
87 | | - -xsl:src/test/resources/xinclude.xsl \ |
88 | | - -s:input-document.xml -o:output-docuent.xml |
89 | | -#+END_SRC |
90 | | - |
91 | | -The =-init:= option will make sure that Saxon can find and use the |
92 | | -extension function. |
93 | | - |
94 | | -* XPointer schemes |
95 | | -:PROPERTIES: |
96 | | -:CUSTOM_ID: h-38009E5E-7A17-49A7-9857-22D7201BB1D8 |
97 | | -:END: |
98 | | - |
99 | | -The standard [[https://www.w3.org/TR/xptr-xmlns/][xmlns()]] and [[https://www.w3.org/TR/xptr-element/][element()]] schemes are supported for XML parsing. An |
100 | | -xpath() scheme is also supported. It evaluates an XPath expression against the document. |
101 | | - |
102 | | -For text documents, [[https://tools.ietf.org/html/rfc5147][RFC 5147]] fragment identifiers are supported. My |
103 | | -own “[[https://norman.walsh.name/2016/09/29/search][search]]” scheme is also supported. The GitHub scheme: L/start/-L/end/ |
104 | | -(for example ~L5-L10~ for lines 5-10) is also supported. |
| 6 | +This project has [https://codeberg.org/ndw/sinclude][moved to Codeberg]. |
0 commit comments