【问题标题】:i want to name my output xml file based on a tag value using XMLT [1.0]?我想使用 XMLT [1.0] 根据标签值命名我的输出 xml 文件吗?
【发布时间】:2020-12-16 03:35:18
【问题描述】:

我的输入代码名为“input.xml”。

这是我的 xsl 代码:

<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:bar="http://www.bar.org">
<xsl:output method="xml"/>  
<xsl:template match="/">
<html>
<body>
     <h2> product </h2>   
            <table border = "1">   
               <tr bgcolor = "pink">   
                  <th>ID</th>   
                  <th>tag</th>   
                  <th>destination</th>   
               </tr>
            <xsl:for-each select = "root/product">
              <xsl:if match=".[tag = 'good']"> 
               <tr>
                    <td><xsl:value-of select="@ID"/></td>
                    <td><xsl:value-of select="tag"/></td>
                    <td><xsl:value-of select="destination"/></td>
               </tr>
              </xsl:if> 
            </xsl:for-each>
            </table>
</body>
</html>
</xsl:template>
</xsl:stylesheet>

我希望根据值将输出文件命名为 good_input.xml。

【问题讨论】:

  • 您不能在 XSLT 1.0 处理器中命名输出文件。
  • 换句话说,您需要确定代码中调用 XSLT 处理器的名称。
  • 实际上,如果您的处理器支持 exsl:document 扩展元素或 XSLT 1.1,这是有可能的。我说的有点,因为这允许创建一个辅助结果文档除了到主要的。
  • @michael.hor257k 你能告诉我更多吗?
  • 您可以在此处阅读:exslt.org/exsl/elements/document/index.html 和此处:w3.org/TR/xslt11/#multiple-output。您使用的是哪种 XSLT 处理器?

标签: xml xslt-1.0


【解决方案1】:

如果 JRE 使用 Xalan Java 2.7 作为 Transformer 的 XSLT 1.0 处理器,那么您应该能够使用专有的 Xalan 扩展元素 redirect:write,如 https://github.com/apache/xalan-j/blob/xalan-j_2_7_1/samples/extensions/1-redir.xsl 所示:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0"
    xmlns:redirect="http://xml.apache.org/xalan/redirect"
    extension-element-prefixes="redirect">

<xsl:template match="/">
  <redirect:write select="concat(root/product/tag, 'result.html')">
    <html>
      ...
    </html>
  </redirect:write>
</xsl:template>

另一方面,当您使用 Java 时,您也可以通过将 Saxon 10 或 9 HE(在 Sourceforge 和 Maven 上可用)放在类路径中来切换到 XSLT 2 或 3 和标准化的 xsl:result-document

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-05-31
    • 2015-09-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-05-16
    • 2012-08-03
    • 1970-01-01
    相关资源
    最近更新 更多