Pass parameter from xquery to xslt -


i transform xml using xslt important variable comes request. have such xquery:

let $transform := doc("projekt.xsl") let $serialization-options := 'method=xml media-type=text/xml omit-xml-declaration=yes indent=no' let $params :=  <parameters>     <param name="output.omit-xml-declaration" value="yes"/>     <param name="output.indent" value="yes"/>     <param name="output.media-type" value="text/html"/>     <param name="output.method" value="xhtml"/>     <param name="param.name" value="topicid" />     <param name="param.select" value="{$topid}"/> </parameters>  return      transform:transform($doc, $transform, $params, $serialization-options) 

file project.xsl here:

<?xml version="1.0" encoding="utf-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/xsl/transform"> <xsl:param name="topicid"/>  <xsl:template match="/">     <xsl:value-of select="$topicid"/>     <xsl:apply-templates select="discussflow/message[@topic=$topicid]"/> </xsl:template>  <xsl:template name="msg" match="//message">     .......... </xsl:template> 

i tu add attribute 'select' to:

<xsl:param name="topicid"/>  

with $topid value specifed in xquery.

i have seen java here: http://www.techrepublic.com/article/pass-parameters-to-xsl-templates-programmatically/1044596 in xquery not want work.

i use exist db 1.4.1

edit:

transform:transform http://exist-db.org/xquery/transform namespace

official documentation here: https://en.wikibooks.org/wiki/xquery/xquery_and_xslt

in xslt doc need use:

<xsl:param name="param.select" select="default value" /> <xsl:param name="output.omit-xml-declaration" select="default value""/> <xsl:param name="output.indent" select="default value"/> <xsl:param name="output.media-type" select="default value"/> <xsl:param name="output.method" select="default value"/> <xsl:param name="param.name" select="default value" /> <xsl:param name="param.select" select="default value"/> 

that is, name of parameter has equal defined in xquery. may use select enter default value, if there no such parameter (or run xslt without request, e.g. testing purposes...)


Comments