Last active
June 6, 2016 19:31
-
-
Save BDF/67b58b6100358230d2ead935cc1edee3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public XdmNode chainNodes(List<XdmNode> nodesToChain) throws SaxonApiException { | |
XdmNode node; | |
switch (nodesToChain.size()) { | |
case 1: | |
node = nodesToChain.get(0); | |
break; | |
case 2: | |
node = append(nodesToChain.get(0), nodesToChain.get(1)); | |
break; | |
default: | |
node = append(nodesToChain.get(0), chainNodes(nodesToChain.subList(1, nodesToChain.size()))); | |
break; | |
} | |
return node; | |
} | |
public XdmNode append(XdmNode nodeOne, XdmNode nodeTwo) throws SaxonApiException { | |
final XdmDestination xdmDestination = new XdmDestination(); | |
final TransformInfo transformInfo = transformService.getXsltExecutable("appender"); | |
final XsltTransformer trans = transformInfo.getXslt().load(); | |
trans.setInitialContextNode(nodeOne); | |
trans.setParameter(new QName("doc"), nodeTwo); | |
trans.setDestination(xdmDestination); | |
trans.transform(); | |
XdmNode result = xdmDestination.getXdmNode(); | |
return result; | |
} | |
/** | |
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> | |
<xsl:param name="doc" as="node()+" /> | |
<xsl:template match="/"> | |
<xsl:copy-of select="."/> | |
<xsl:copy-of select="$doc"/> | |
</xsl:template> | |
</xsl:stylesheet> | |
*/ | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment