The JDeveloper Mapper for XML Transformations (XSLT) is a powerful tool to create XML Transformations using a graphical interface and auto-mapping. Unfortunately it has a limited scope of functions that are supported and mappings that are a bit more complex cannot be implemented.
Is it possible to use JDeveloper with the full scope of available XSLT-functions? Or do I have to choose between either using the JDeveloper Mapper or having access to all XSLT functions?
You can always get the full power by using the Source View and modify the code directly. But then, when you move back to the Design View, JDeveloper tells you that there are errors in the code and you cannot use the Design View until you fix them.
Therefore, a possible solution is to do all the mapping that is possible in the Graphical View and then move to the Source View and implement the more complex mappings and XSLT functions there. If you do so, you can't move back to the Graphical View though.
A solution that I found works very well for me is the following: I introduced new tags that are as follows:
<!-- show-code --> <!--
--> <!-- /show-code -->
and
<!-- hide-code -->
<!-- /hide-code -->
Between the first two tags, you put the solution for your code block that is the final solution, using all the complex XSLT 2.0 / XSLT 3.0 functions that you want. Before or after that you put the second pair of tags and in between a simple solution that does somehow the same, but in a simpler way and such that JDeveloper still understands it.
Since the real solution is in comments, JDeveloper will be able to switch to Design View and you can still modify other parts of your mapping there.
Performing the Transformation
Now to perform the real transformation, you pre-process the XSLT code with a replace-function. In my case this is the following Java-code:
private static String applyCodeReplacement(String xml) {
// Replacing string using regular expressions
xml = xml.replaceAll( "<!--\\s*show-code\\s*-->\\s*<!--","");
xml = xml.replaceAll("-->\\s*<!--\\s*/show-code\\s*-->","");
xml = xml.replaceAll("<!--\\s*hide-code\\s*-->", "<!--");
xml = xml.replaceAll("<!--\\s*/hide-code\\s*-->", "-->");
return xml;
}
This will remove all simple code blocks and integrate all the complex ones. Now you are left with an XSLT file that does exactly what you want it to do. And you are still able to open and modify it in the Design View of JDeveloper.