Pass document as parameter to XSL Translation in Java

后端 未结 4 1617
无人及你
无人及你 2021-01-12 11:01

I\'m working on addition internationalization to my XSL. I\'ve seen plenty of examples of creating a dictionary.xml file and loading it into my XSL via document(\'dictionar

4条回答
  •  伪装坚强ぢ
    2021-01-12 11:39

    Passing a DOM Document node as a parameter to a Saxon transformation should work (DOM is not the most efficient tree representation, by a long way, but it should work). So should passing DOMSource that wraps the DOM Document. I usually start by doing xsl:copy-of select="$doc", and you seem to have done this and confirmed that the value is being passed in correctly. If you're not getting anything in response to XPath selections within the document, this usually means that the XPath expressions are wrong. The most usual reasons are forgetting about the root (document) node, and forgetting about namespaces. But I'm afraid there's no evidence of such mistakes in the code you have shown us - assuming the DOM reflects the XML you have shown in your post.

    Your post suggests that you have build the DOM Document programmatically. It's possible that you have created a DOM that Saxon can't process for some reason: DOM interfaces are not very robust and there are sometimes difficulties when people use a DOM implementation that hasn't been tested with Saxon.

    You could also test your stylesheet by running it from the command line - you can supply the value of the $dictionary parameter using +dictionary=dict.xml (the leading '+' causes it to be recognized as the name of a file that needs to be parsed).

提交回复
热议问题