Skip to content

Commit 41027d8

Browse files
authored
Merge pull request #15 from ndw/string-keys
Allow string keys in the extension function map
2 parents bf61b05 + 55c3e14 commit 41027d8

File tree

3 files changed

+16
-39
lines changed

3 files changed

+16
-39
lines changed

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
basename=sinclude
22
sincludeTitle=Saxon XInclude
3-
sincludeVersion=5.2.1
3+
sincludeVersion=5.2.2
44

55
saxonVersion=11.5

src/main/java/com/nwalsh/xslt/XIncludeFunction.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,12 +83,7 @@ public Sequence call(XPathContext xpathContext, Sequence[] sequences) throws XPa
8383

8484
boolean fixupBase = getBooleanOption(_fixup_xml_base, true);
8585
boolean fixupLang = getBooleanOption(_fixup_xml_lang, true);
86-
87-
boolean defaultTrimText = false;
88-
boolean trimText = defaultTrimText;
89-
if (getBooleanOption(_trim_text, false)) {
90-
trimText = true;
91-
}
86+
boolean trimText = getBooleanOption(_trim_text, false);
9287

9388
XdmNode doc = new XdmNode(source);
9489
XInclude xinclude = new XInclude();
@@ -129,7 +124,20 @@ private HashMap<QName,String> parseMap(MapItem item) throws XPathException {
129124
AtomicValue next = aiter.next();
130125
while (next != null) {
131126
final QName key;
132-
if (next.getItemType() == BuiltInAtomicType.QNAME) {
127+
if (next.getItemType() == BuiltInAtomicType.STRING) {
128+
String keyname = next.getStringValue();
129+
if (keyname.contains(":")) {
130+
throw new IllegalArgumentException("Option map string keys must not contain a colon");
131+
}
132+
if (keyname.equals(_fixup_xml_base.getLocalName())
133+
|| keyname.equals(_fixup_xml_lang.getLocalName())
134+
|| keyname.equals(_trim_text.getLocalName())) {
135+
key = new QName("", keyname);
136+
} else {
137+
throw new IllegalArgumentException("Unrecognized option map string key: " + keyname);
138+
}
139+
140+
} else if (next.getItemType() == BuiltInAtomicType.QNAME) {
133141
key = NamespaceUtils.qName((QNameValue) next);
134142
} else {
135143
throw new IllegalArgumentException("Option map keys must be QNames");

src/test/java/com/nwalsh/xslt/ExtFunctionTest.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -152,35 +152,4 @@ private XdmNode applyStylesheet(String stylesheet, String document) throws Saxon
152152
throw new RuntimeException("Value returned where node was expected");
153153
}
154154
}
155-
156-
public void foo() {
157-
String stylesheet = "";
158-
stylesheet += "<xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform'\n";
159-
stylesheet += " xmlns:ext='http://nwalsh.com/xslt'\n";
160-
stylesheet += " version='3.0'>\n\n";
161-
stylesheet += "<xsl:output method='text' encoding='utf-8'/>\n\n";
162-
stylesheet += "<xsl:template match='/' name='main'>\n";
163-
stylesheet += " <xsl:value-of select=\"'hello world'\"/>\n";
164-
stylesheet += "</xsl:template>\n\n";
165-
stylesheet += "</xsl:stylesheet>\n";
166-
167-
ByteArrayInputStream bais = new ByteArrayInputStream(
168-
stylesheet.getBytes(StandardCharsets.UTF_8));
169-
170-
try {
171-
RawDestination result = new RawDestination();
172-
XsltCompiler compiler = processor.newXsltCompiler();
173-
XsltExecutable exec = compiler.compile(new SAXSource(new InputSource(bais)));
174-
XsltTransformer transformer = exec.load();
175-
transformer.setDestination(result);
176-
transformer.setInitialTemplate(new QName("", "main"));
177-
transformer.transform();
178-
XdmValue value = result.getXdmValue();
179-
System.err.println(value);
180-
} catch (SaxonApiException sae) {
181-
sae.printStackTrace();
182-
TestCase.fail();
183-
}
184-
}
185-
186155
}

0 commit comments

Comments
 (0)