Setting hidden xslt value from java

New in xslt, I wanted to set string value from java for 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 the same way as html, or is it different from evaluation? Thanks for your help and time.

+3


source to share


1 answer


Yes, you can pass values ​​to your XSLT using parameters. What you would do is define a parameter at the top of your XSLT file:

<xsl:param name="trackValue" />

      

And then you will pass the value for that when you run the conversion:

TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer xsltTransformer = transformerFactory.newTransformer(xsltSource);
xsltTransformer.setParameter("trackValue", parameterValue);

      



Then you can use it wherever you want (note the use of the $ sign):

<xsl:attribute name="value"><xsl:value-of select="$trackValue"/></xsl:attribute>

      

Converting XSL to Java with parameters

+2


source







All Articles