Question

Does anyone have an example of how to reference a property on the xslt mediator within the xslt itself?

The documentation says

property - Allows optional parameters to be passed into the transformations. These properties are corresponding to the XSL parameters and can be accessed during transformation.

I cannot find an example of how to refer to this from within the xslt itself. I've added the namespace http://ws.apache.org/ns/synapse to the xslt document but it cannot resolve the get-property() function.

Was it helpful?

Solution

Say you have 2 properties in your synapse config. Then you want to pass them to XSLT and refer it from there. So inside the synapse config,

<property name="email" expression="//request/email"/>
<property name="name" expression="//request/name"/>

<xslt key="orderTransformer">
             <property name="email" expression="get-property('email')"/>
             <property name="name" expression="get-property('name')"/>
</xslt>

Now insdie the XSLT here is how you refer them. First Define them as two params.

<xsl:param name="email"/>
<xsl:param name="name"/>

Use them as $email, $name in where u need.

Example XSLT

<xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:ns1="http://wso2.org/sample/shop/order">
    <xsl:output method="xml" omit-xml-declaration="yes"/>
    <xsl:param name="email"/>
    <xsl:param name="name"/>
    <xsl:template match="/">
        <xsl:apply-templates select="//ns1:AddOrder"/>
    </xsl:template>
    <xsl:template match="ns1:AddOrder">
        <ns1:AddOrder>
            <ns1:email>
                <xsl:value-of select="$email"/>
            </ns1:email>
            <ns1:name>
                <xsl:value-of select="$name"/>
            </ns1:name>
        </ns1:AddOrder>
    </xsl:template>
</xsl:stylesheet>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top