我使用以下xsl从wsdl
中检索架构类型<?xml version="1.0" encoding="UTF-8"?><xsl:transform version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" encoding="UTF-8"/>
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="//*[local-name()='schema' and namespace-uri()='http://www.w3.org/2001/XMLSchema']">
<xsl:copy-of select="."></xsl:copy-of>
</xsl:template></xsl:transform>
以及以下java代码段
tFactory = TransformerFactory.newInstance();
xslSource = new StreamSource("resources/input/wsdl2xsd.xsl");
xmlSource = new StreamSource(wsdlURI.toString());
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
outStream = new BufferedOutputStream(byteArrayOutputStream);
transformer = tFactory.newTransformer(xslSource);
transformer.transform(xmlSource, new StreamResult(outStream));
System.out.print(new String(byteArrayOutputStream.toByteArray()));
但是由于某种原因,我在'schema'元素结束后用一些奇怪的字符串获得了很多空白空间?它适用于一些wslds。我试过eBays public wsdl,这个很棒:
http://developer.ebay.com/webservices/741/eBaySvc.wsdl
在'schema'元素之后输出字符串。
答案 0 :(得分:0)
您当前的样式表代码依赖the built-in templates来访问您自己的模板,这样您就可以从文本节点获得输出。
您似乎不希望这样,您可以将<xsl:template match="text()"/>
添加到您的代码中,或者您可能需要一种不同的方法,例如您可以<xsl:template match="/"><xsl:copy-of select="//xs:schema" xmlns:xs="http://www.w3.org/2001/XMLSchema"/></xsl:template>
。