New to xslt, I wanted to set a value of string from java to this variable
<xsl:element name="input">
<xsl:attribute name="type">hidden</xsl:attribute>
<xsl:attribute name="name">trackId</xsl:attribute>
<xsl:attribute name="value"><xsl:value-of select="trackValue"/></xsl:attribute>
</xsl:element>
Is it in same manner as html or is it different apprach? Thanks for help and time.
Yes, you can pass values into your XSLT using parameters. What you would do is define a parameter near the top of your XSLT file:
<xsl:param name="trackValue" />
And then you would pass in a value for this when you run the transform:
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer xsltTransformer = transformerFactory.newTransformer(xsltSource);
xsltTransformer.setParameter("trackValue", parameterValue);
Then you can use it wherever you want to (note the use of the $ sign):
<xsl:attribute name="value"><xsl:value-of select="$trackValue"/></xsl:attribute>
XSL Transformation in Java with parameters
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With