I want the $content to be the expected string. I know that copy-of instead of value-of $content produces the expected string. But how do I not use copy-of and pass it to say a java extension function?
I asked a different related question here.
XML
<?xml version="1.0"?>
<a>
<b c="d"/>
<b c="d"/>
<b c="d"/>
</a>
XSL
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template name="foo">
<xsl:param name="content"></xsl:param>
<!-- <xsl:copy-of select="$content"></xsl:copy-of> -->
<!-- copy-of produces the expected string here, but how to pass to Java -->
<xsl:value-of select="java:someMethod($content)" />
<!-- I want the content to be the expected string -->
</xsl:template>
<xsl:template match="/">
<xsl:call-template name="foo">
<xsl:with-param name="content">
<xsl:for-each select="a/b">
<e>
<xsl:value-of select="@c" />
</e>
</xsl:for-each>
</xsl:with-param>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
Desired String to be passed to Java extension function from $content.
<?xml version="1.0"?>
<e>d</e>
<e>d</e>
<e>d</e>
PS: Calling foo is mandatory.
Ultimately, my objective is to emulate result-document in XSLT 1.0 with extension function.
Calling Java extension functions depends on which XSLT processor you are using, which you haven’t told us. If you use Java’s TransformerFactory you will get whatever is on the classpath, for example the built-in version of Xalan, the Apache version of Xalan, or Saxon.
Your description suggests you want to pass a string containing lexical XML to your Java extension function. That implies you need to serialize a node to a string. That can’t be achieved without an extension function such as saxon:serialize(). It’s probably easier to pass the node to your Java method, and have the Java method do the serialization.