Actions
Bug #6460
openPossible lazy evaluation side-effect
Status:
New
Priority:
Low
Assignee:
-
Category:
-
Sprint/Milestone:
-
Start date:
2024-06-26
Due date:
% Done:
0%
Estimated time:
Legacy ID:
Applies to branch:
Fix Committed on Branch:
Fixed in Maintenance Release:
Platforms:
Description
1. Summary¶
I'm developing a stylesheet that inputs DITA merged middle file (generated by DITA Open Toolkit 4.2.3) and outputs text file using Saxon-HE-12.4.jar. I encountered the phenomenon that seems to be caused by variable lazy eveluation.
2. Code¶
<xsl:template match="*[@class => contains-token('map/topicref')][*[@class => contains-token('map/topicmeta')]/*[@class => contains-token('pmap-d/bookref')]]" mode="MODE_EXTRACT_IMAGE" priority="40">
<xsl:variable name="topicRef" as="element()" select="."/>
<xsl:variable name="topicMeta" as="element()" select="$topicRef/*[@class => contains-token('map/topicmeta')]"/>
<xsl:variable name="annotatedXmlPath" as="xs:string" select="$topicRef/*[@class => contains-token('map/topicmeta')]/*[@class => contains-token('pmap-d/bookref')]/@href"/>
<xsl:variable name="annotatedXmlPathDecoded" as="xs:string" select="uriutil:decodeURI($annotatedXmlPath)"/>
<xsl:variable name="annotatedXmlPathNative" as="xs:string" select="ahf:pathToNativeStyle($annotatedXmlPathDecoded, $pIsWindows) => ahf:substringBeforeLast($pFileSep)"/>
<xsl:message select="'$annotatedXmlPath=' || $annotatedXmlPath"/>
<xsl:message select="'$annotatedXmlPathDecoded=' || $annotatedXmlPathDecoded"/>
<!--xsl:message select="'$annotatedXmlPathNative=' || $annotatedXmlPathNative"/-->
<xsl:next-match>
<xsl:with-param name="prmAnnotatedXmlPathNative" tunnel="yes" select="$annotatedXmlPathNative"/>
</xsl:next-match>
</xsl:template>
"uriutil:decodeURI($annotatedXmlPath)" is the simple Java extension function.
// URIUtil.java
package com.antennahouse.xslt.extension;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;
public class URIUtil {
/**
* Decode URI String
*/
public static String decodeURI(String url) throws UnsupportedEncodingException{
String result=java.net.URLDecoder.decode(url, StandardCharsets.UTF_8.name());
return result;
}
}
// DecodeURIFunctionDefinition.java
package com.antennahouse.xslt.extension;
import net.sf.saxon.expr.XPathContext;
import net.sf.saxon.lib.ExtensionFunctionCall;
import net.sf.saxon.lib.ExtensionFunctionDefinition;
import net.sf.saxon.om.Sequence;
import net.sf.saxon.om.StructuredQName;
import net.sf.saxon.trans.XPathException;
import net.sf.saxon.value.SequenceType;
import net.sf.saxon.value.StringValue;
/**
* Function definition for URIUtil.decodeURI()
* @see https://www.saxonica.com/html/documentation10/extensibility/integratedfunctions/ext-full-J.html
* @see https://www.dita-ot.org/dev/topics/implement-saxon-extension-functions.html
*/
public class DecodeURIFunctionDefinition extends ExtensionFunctionDefinition{
public StructuredQName getFunctionQName() {
return new StructuredQName("", "java:com.antennahouse.xslt.extension.URIUtil", "decodeURI");
}
public SequenceType[] getArgumentTypes() {
return new SequenceType[] {SequenceType.SINGLE_STRING};
}
public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) {
return SequenceType.SINGLE_STRING;
}
public ExtensionFunctionCall makeCallExpression() {
return new ExtensionFunctionCall() {
@Override
public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException {
try {
String arg = arguments[0].toString();
String result = URIUtil.decodeURI(arg);
return StringValue.makeStringValue(result);
} catch (Exception ex) {
throw new XPathException(ex);
}
}
};
}
}
3. Result¶
When I run above code¶
Got the following text file
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書①\topic\images_基本設計書①\下線入りダミー画像.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書①\topic\images_基本設計書①\ダミー.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書②\..\基本設計書①\topic\images_基本設計書①\下線入りダミー画像.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書②\..\基本設計書①\topic\images_基本設計書①\ダミー.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書③\..\基本設計書①\topic\images_基本設計書①\下線入りダミー画像.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\..\basedesign\基本設計書③\..\基本設計書①\topic\images_基本設計書①\ダミー.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
The xsl:message result
$annotatedXmlPath=../../basedesign/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A0/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A0-annotated.xml
$annotatedXmlPathDecoded=../../basedesign/基本設計書①/基本設計書①-annotated.xml
$annotatedXmlPath=../../basedesign/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A1/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A1-annotated.xml
$annotatedXmlPathDecoded=../../basedesign/基本設計書②/基本設計書②-annotated.xml
$annotatedXmlPath=../../basedesign/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A2/%E5%9F%BA%E6%9C%AC%E8%A8%AD%E8%A8%88%E6%9B%B8%E2%91%A2-annotated.xml
$annotatedXmlPathDecoded=../../basedesign/基本設計書③/基本設計書③-annotated.xml
When I remove two xsl:message and run above code¶
I got the following text file.
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\\topic\images_基本設計書①\下線入りダミー画像.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\\topic\images_基本設計書①\ダミー.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\\..\基本設計書①\topic\images_基本設計書①\下線入りダミー画像.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\\..\基本設計書①\topic\images_基本設計書①\ダミー.svg;D:\My_Documents\XML2023\ah\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\..\基本設計書①\topic\images_基本設計書①
Difficulty¶
The result text file is composed of lines that describe image file path to copy and destination folder. In the first result, the copying ant step ended normaly. But in the latter case the step ended with exception that describes "Source file does not exists".
D:\DITA-OT\dita-ot-4.2.3\plugins\org.dita.base\build.xml:150: The following error occurred while executing this line:
D:\DITA-OT\dita-ot-4.2.3\plugins\com.antennahouse.map.expand\build.xml:108: The following error occurred while executing this line:
D:\DITA-OT\dita-ot-4.2.3\plugins\com.antennahouse.map.expand\build.xml:211: Error occured during copy. Message='Source file does not exists! Path='D:\My_Documents\XML2023\nbi\diffs\diff-2024-06-24\10_評価データ\parameter\●●書パラメータ表①\\topic\images_基本設計書①\下線入りダミー画像.svg''
at org.apache.tools.ant.ProjectHelper.addLocationToBuildException(ProjectHelper.java:582)
at org.apache.tools.ant.taskdefs.Ant.execute(Ant.java:440)
at org.apache.tools.ant.taskdefs.CallTarget.execute(CallTarget.java:106)
at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:299)
at jdk.internal.reflect.GeneratedMethodAccessor6.invoke(Unknown Source)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:568)
at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.java:99)
at org.apache.tools.ant.Task.perform(Task.java:350)
at org.apache.tools.ant.Target.execute(Target.java:449)
at org.apache.tools.ant.Target.performTasks(Target.java:470)
at org.apache.tools.ant.Project.executeSortedTargets(Project.java:1401)
at org.apache.tools.ant.Project.executeTarget(Project.java:1374)
at org.apache.tools.ant.helper.DefaultExecutor.executeTargets(DefaultExecutor.java:41)
at org.apache.tools.ant.Project.executeTargets(Project.java:1264)
at org.dita.dost.invoker.Main.runBuild(Main.java:853)
at org.dita.dost.invoker.Main.startAnt(Main.java:240)
at org.apache.tools.ant.launch.Launcher.run(Launcher.java:284)
at org.apache.tools.ant.launch.Launcher.main(Launcher.java:101)
How do I solve this problem??
Files
Please register to edit this issue
Actions