【发布时间】:2015-07-03 14:07:01
【问题描述】:
设置: Apache Xalan 2.7.1
输入:
<?xml version="1.0" encoding="UTF-8"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
main.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xpi="http://xml.apache.org/xalan/PipeDocument">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xpi:pipeDocument source="." >
<stylesheet href="second.xslt"/>
</xpi:pipeDocument>
</xsl:template>
</xsl:stylesheet>
second.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xsl:value-of select="note/to" />
</xsl:template>
</xsl:stylesheet>
输出:
<?xml version="1.0" encoding="UTF-8"?><xpi:pipeDocument xmlns:xpi="http://xml.apache.org/xalan/PipeDocument" source=".">
<stylesheet href="second.xslt"/>
</xpi:pipeDocument>
期望的输出:
<?xml version="1.0" encoding="UTF-8"?>
Tove
问题:
来自这里:https://xml.apache.org/xalan-j/apidocs/org/apache/xalan/lib/PipeDocument.html
我真的为这个问题摸不着头脑。如何正确使用
source和target??我希望当前输入 xml 为
source和output,就像原来一样,标准output.xml。注意:仅支持 xslt 1.0 解决方案
【问题讨论】:
-
参见w3.org/TR/xslt#extension,如果您想告诉处理器该元素是用作指令的扩展元素,那么您需要首先声明
<xsl:stylesheet extension-element-prefixes="xpi" ...>。 -
而
<xpi:pipeDocument source="." >应该是<xpi:pipeDocument source="{.}" >,不是吗? -
我不介意
prefixes输出的实际值是问题所在。管道转换没有调用second.xslt。 -
告诉处理器您希望将
xpi:pipeDocument视为指令而不是结果元素,您必须声明<xsl:stylesheet extension-element-prefixes="xpi" ...>。我不明白为什么你告诉我们你“不介意前缀”,而不是这样做,除非你把exclude-result-prefixes和extension-element-prefixes混淆了。但它们是完全不同的属性。 -
好吧,这有点误会。您对
extension-element-prefixes的看法是 100% 正确的。经过一些测试,我会更新 q