我将样式表和输入流传递给Transformer
类以获取输出 XML。
传递给 xmlns 的相对变量不会在结果中被替换。
输入流:
"http://www.abc.com/foo/bar"
+"EventCommon"
+"application,xsd:string"
+"companyId,xsd:string"
+"operator,xsd:string"
+"today,xsd:date"
+"transactionStage,xsd:string"
样式表:
<xsl:stylesheet
version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
>
<xsl:output method="xml" encoding="UTF-8" indent="yes" />
<xsl:template match="/">
<xsl:variable name="var_main_namespace" select="array/data[@attribute=1][@value=1][@subvalue=1]" />
<xsd:schema xmlns="($var_main_namespace)" targetNamespace="{$var_main_namespace}" elementFormDefault="qualified" />
</xsl:template>
</xsl:stylesheet>
输出 XML:
<xsd:schema
xmlns="($var_main_namespace)"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.abc.com/foo/bar"
elementFormDefault="qualified"
/>
代码片段:
TransformerFactory tFactory = TransformerFactory.newInstance();
StreamSource sc = new StreamSource(new ByteArrayInputStream(new String(c).getBytes()));
Transformer transformer = tFactory.newTransformer(sc);
ByteArrayOutputStream outputxml = new ByteArrayOutputStream();
transformer.transform(
new StreamSource(
new ByteArrayInputStream(new String(c2).getBytes())
),
new StreamResult(outputxml)
);
任何帮助表示赞赏