0

我正在尝试编写两个 XSL 文件,以实现以下目标:

  1. 它应该加密输入文档。

  2. 它应该对 XML 文档进行二进制编码。

1) 的示例输出

<Response>
  <encryptedData>e070dee5cb4688c608ee</encryptedData>
</Response>

2) 的示例输出

<Response>
   <compressedData>ASCDee5cb4688c608ee</compressedData>
</Response>

对于功能 #1,我有一个 Java 扩展函数,它接受字符串输入并返回加密字符串。但我不知道如何将输入文档作为字符串传递给扩展函数。

对于功能 #2,我不确定如何将输入转换为二进制 XML。

4

2 回答 2

0

我只能回答您关于如何从 XSLT 调用 java 函数的第一个问题。在您的样式表声明中,您必须定义一个命名空间,例如xmlns:filecounter="mappings.GenerateSequenceNumber"

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:filecounter="mappings.GenerateSequenceNumber"
exclude-result-prefixes="filecounter" version="1.0">
<xsl:output indent="yes"/>

In this case the java function is in the package "mappings" and the java class is called "GenerateSequenceNumber".

When calling the java function in your stylesheet you do for example:

<xsl:value-of select="filecounter:getSequenceNumber('countit',3)"/>

So you call the method "getSequenceNumber" in your java class and pass any variables that the java function needs in the brackets.

Unfortunately I can't help you with your second question.

于 2012-08-30T07:12:47.700 回答
0

XSLT cannot exactly reproduce the original string representing an XML document -- due to various lexical peculiarities (and substitution of entity referencies) that are not able to reconstruct from the XmlDocument produced by the XML parser -- which is the input that an XSLT processor sees.

You can pass to the extension function the document object (/) and then the Java function can use a method like OuterXml() or InnerXml() to get one possible representation of the XML document.

于 2012-08-30T13:12:06.223 回答