XSL Transformation in Java with parameters

前端 未结 2 1538
借酒劲吻你
借酒劲吻你 2020-11-30 05:00

I have a xsl file where i need to use parameters from an external source. I am using Java and my code looks something like this:

TransformerFactory transform         


        
相关标签:
2条回答
  • 2020-11-30 05:25

    rsp's answer was spot on. Thanks. Just want to add that you cannot pass a parameter to a variable in the same way (I am setting parameters via Java's TransformerFactory).

    I made the mistake of thinking variables and params were interchangeable :)

    0 讨论(0)
  • 2020-11-30 05:36

    If you pass a parameter like:

    transformer.setParameter("render_id", "1234");
    

    the parameter can be picked up by the transform:

    <xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
    
    <xsl:output method="xml" encoding="UTF-8" omit-xml-declaration="yes"/>
    
    <!-- Receives the id of the menu being rendered. -->
    <xsl:param name="render_id" />
    
    0 讨论(0)
提交回复
热议问题