【问题标题】:XSLT : pipeDocumentXSLT:管道文档
【发布时间】: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>

ma​​in.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

我真的为这个问题摸不着头脑。如何正确使用sourcetarget??

我希望当前输入 xml 为 sourceoutput,就像原来一样,标准 output.xml

注意:仅支持 xslt 1.0 解决方案

【问题讨论】:

  • 参见w3.org/TR/xslt#extension,如果您想告诉处理器该元素是用作指令的扩展元素,那么您需要首先声明&lt;xsl:stylesheet extension-element-prefixes="xpi" ...&gt;
  • &lt;xpi:pipeDocument source="." &gt; 应该是&lt;xpi:pipeDocument source="{.}" &gt;,不是吗?
  • 我不介意prefixes 输出的实际值是问题所在。管道转换没有调用second.xslt
  • 告诉处理器您希望将xpi:pipeDocument 视为指令而不是结果元素,您必须声明&lt;xsl:stylesheet extension-element-prefixes="xpi" ...&gt;。我不明白为什么你告诉我们你“不介意前缀”,而不是这样做,除非你把exclude-result-prefixesextension-element-prefixes 混淆了。但它们是完全不同的属性。
  • 好吧,这有点误会。您对extension-element-prefixes 的看法是 100% 正确的。经过一些测试,我会更新 q

标签: xml apache xslt xalan


【解决方案1】:

考虑以下模板作为答案

请注意,您需要具有正确的文件夹结构才能使此转换生效。 (second.xslt, thrid.xslt, 输出, 输入xmls)

<?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"
    extension-element-prefixes="xpi">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes" />


  <xsl:template match="/">      
        <xpi:pipeDocument source="'source_file'" target="output_file">
               <stylesheet href="second.xslt"/>
               <stylesheet href="third.xslt"/>
        </xpi:pipeDocument>
    </xsl:template>


</xsl:stylesheet>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-21
    • 2012-04-12
    相关资源
    最近更新 更多