0
votes

I need to pass a node as a parameter to an XSL stylesheet. The issue is that the parameter gets sent as a string. I have seen the several SO questions regarding this topic, and I know that the solution (in XSLT 1.0) is to use an external node-set() function to transform the string to a node set.

My issue is that I am using eXist DB I cannot seem to be able to get its XSLT processor to locate any such function. I have tried the EXSLT node-set() from the namespace http://exslt.org/common as well as both the Saxon and Xalan version (I think eXist used to use Xalan but now it might be Saxon).

Are these extensions even allowed in the XSLT processor used by eXist? If not, is there something else I can do?

2
Well, you can first check details of your used XSLT processor with a stylesheet like home.arcor.de/martin.honnen/xslt/processorTest3.xml to output properties like system-property('xsl:vendor') and system-property('xsl:product-version'). As for your current attempts, are you using Java code to perform the XSLT transformation, or XQuery? Consider to show details of that code passing the parameter and running the transformation. - Martin Honnen
You don't want to read other similar SO questions/answers unless they relate specifically to eXist, because the way of passing parameters to an XSLT transformation depends on the details of the API offered by the particular product, and that varies from one product to another. And it is NOT the purpose of the node-set() function to parse XML supplied as a string, though some implementations do that. - Michael Kay
exist-db.org/exist/apps/fundocs/view.html?uri=http://… says about the parameters "Stylesheet parameters may be passed in the third argument using an XML fragment with the following structure: <parameters><param name="param-name1" value="param-value1"/></parameters>". That looks as if parameters, at least for the transform function, are simply name/value string pairs. - Martin Honnen
And github.com/eXist-db/exist/blob/develop/src/org/exist/xquery/… seems does seem to confirm that parameters are treated as java.util.Properties. But hopefully some exist user or developer can provide a more informed answer. - Martin Honnen
@Martin Honnen Yes, I am indeed using the XQuery function transform:transform() to run the transformation. And I think you're right. The <param> seems strip any XML tags that are passed to it. So I don't think the node can be recreated at all. - pajevic

2 Answers

1
votes

To reference or transform documents from the database, you should pass the path as a parameter to the transformation, and then refer to it using a parameter and variable

(: xquery :)

let $path-to-document := "/db/test/testa.xml"
let $stylesheet := 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="source" required="no"/>
    <xsl:variable name="error"><error>doc not available</error></xsl:variable>
    <xsl:variable name="theDoc" select="if (doc-available($source)) then doc($source) else $error"/>
    <xsl:template match="/">
       <result><xsl:value-of select="$source"/> - <xsl:value-of select="node-name($theDoc/*)"/></result>
    </xsl:template>
</xsl:stylesheet>


return transform:transform(<dummy/>,$stylesheet, <parameters><param    name="source" value="xmldb:exist://{$path-to-document}"/></parameters>)
1
votes

As per Martin Honnen's comments I don't think it is possible to pass an XML node via the <parameters> structure of the transform:transform() function in eXist. The function seems to strip away any XML tags passed to it as a value.

As a workaround I will wrap both my input XML and my parameter XML into a root element and pass that as input to the transform function.