How to access xsl:param in an attribute of xsl:output?

后端 未结 2 1178
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-27 02:32

I want to allow the transformer to set a param in my stylesheet to specify how many spaces of indentation are desired. I have tried all of the suggestions by @Dimitre Novatchev

2条回答
  •  终归单人心
    2021-01-27 03:08

    It does not appear that Xalan supports attribute value templates for the value of the xalan:indent-amount attribute.

    I get a warning message that attribute value templates are not supported in xsl:output in XSLT 1.0. Apparently, they are supported in 1.1 (which should not be used, as it was abandoned by the W3C), but Xalan does not appear to resolve the parameter value in the AVT in that particular attribute.

    When I attempt to use the parameter value in an AVT, it returns the error:

    E For input string "{$indent}"
    

    One possible workaround would be to use entities and generate a DTD. Rather than pass in the indent value as a param, have your XSLT reference a DTD. Generate the DTD file with the indent value that you need and then invoke the XSLT.

    For example, create a DTD file like this (assume named "indent.dtd"):

    
    

    And then reference the DTD in your XSLT like this (assume that indent.dtd is located in the same folder, or you could adjust the path):

    
    
        
    
    
    

    Another workaround would be to generate an XSLT with the desired value for the xalan:indent-amount first, and then transform your XML with the newly generated XSLT.

提交回复
热议问题