【问题标题】:Why does Saxon evaluate the result-document URI to be the same?为什么 Saxon 评估结果文档 URI 相同?
【发布时间】:2010-06-04 12:25:33
【问题描述】:

我的 XSL 源文档如下所示

<Topology>
<Environment>
    <Id>test</Id>
    <Machines>
        <Machine>
            <Id>machine1</Id>
            <modules>
                <module>m1</module>
                <module>m2</module>
            </modules>
        </Machine>
    </Machines>
</Environment>
<Environment>
    <Id>production</Id>
    <Machines>
        <Machine>
            <Id>machine1</Id>
            <modules>
                <module>m1</module>
                <module>m2</module>
            </modules>
        </Machine>
        <Machine>
            <Id>machine2</Id>
            <modules>
                <module>m3</module>
                <module>m4</module>
            </modules>
        </Machine>
    </Machines>
</Environment>
</Topology>

我想为每台机器创建一个结果文档,因此我使用以下样式表,将 modelDir 作为结果文档的路径作为参数。

<xsl:output method="xml" version="1.0" encoding="UTF-8" 
            indent="yes" name="myXML" doctype-system="http://java.sun.com/dtd/properties.dtd"/>

<xsl:template match="/">
    <xsl:for-each-group select="/Topology/Environment/Machines/Machine" group-by="Id">

        <xsl:variable name="machine" select="Id"/>
        <xsl:variable name="filename" select="concat($modelDir,$machine,'.xml')" />

        <xsl:message terminate="no">Writing machine description to <xsl:value-of select="$filename"/></xsl:message>

        <xsl:result-document href="$filename" format="myXML">

            <xsl:variable name="currentMachine" select="Id"/>
            <xsl:for-each select="current-group()/LogicalHosts/LogicalHost">
                <xsl:variable name="environment" select="normalize-space(../../../../Id)"/>
                <xsl:message terminate="no">Module <xsl:value-of select="."/> for <xsl:value-of select="$environment"/></xsl:message>
            </xsl:for-each>

        </xsl:result-document>

     </xsl:for-each-group>
</xsl:template>

正如我的消息显示的那样,这似乎工作正常 - 如果 saxon 不会将结果文档的 URI 评估为相同并因此给出以下输出。

Writing machine description to target/build/model/m1.xml
Module m1 for test
Module m2 for test
Module m1 for production
Module m2 for production
Writing machine description to target/build/model/m2.xml
Error at xsl:result-document on line 29 of file:/C:/Projekte/.../machine.xsl:
  XTDE1490: Cannot write more than one result document to the same URI, or write to a URI
  that has been read:
  file:/C:/Projekte/.../$filename
file:/C:/Projekte/.../machine.xsl(29,-1) : here Cannot write more than one result document to the same URI, or write to a URI that has been read: file:/C:/Projekte/.../$filename
; SystemID: file:/C:/Projekte/.../machine.xsl; Line#: 29; Column#: -1
net.sf.saxon.trans.DynamicError: Cannot write more than one result document to the same URI, or write to a URI that has been read: file:/C:/Projekte/.../$filename
    at net.sf.saxon.instruct.ResultDocument.processLeavingTail(ResultDocument.java:300)
    at net.sf.saxon.instruct.Block.processLeavingTail(Block.java:365)
    at net.sf.saxon.instruct.Instruction.process(Instruction.java:91)

关于如何解决这个问题的任何想法?

【问题讨论】:

    标签: xslt-2.0 saxon xslt


    【解决方案1】:

    您正在为@file 指定一个变量$filename,但没有包含在{} 中,因此它每次都将其评估为字符串“$filename”(这是相同的URI,因此出现错误) .

    您需要将其评估为 Attribute Value Template

    <xsl:result-document href="{$filename}" format="myXML">
    

    【讨论】:

    • 为什么我没有意识到这一点?非常感谢您打开我的盲目思维 ;-) 好:参考 AVT。
    猜你喜欢
    • 1970-01-01
    • 2013-01-23
    • 2021-12-16
    • 2014-10-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-08-16
    • 1970-01-01
    相关资源
    最近更新 更多