Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting xslt hidden value from java

Tags:

java

xslt

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.

like image 774
userJ Avatar asked Dec 21 '25 01:12

userJ


1 Answers

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

like image 126
JLRishe Avatar answered Dec 22 '25 16:12

JLRishe