Почему Saxon оценивает URI документа результата как одинаковый?

Мой исходный документ 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)

Есть идеи, как это решить?


person Jan    schedule 04.06.2010    source источник


Ответы (1)


Вы указываете переменную $filename для @file, но не обернули в {}, поэтому она каждый раз оценивает ее как строку «$ filename» (это тот же самый URI, следовательно, ошибка).

Его необходимо оценить как шаблон значения атрибута .

<xsl:result-document href="{$filename}" format="myXML">
person Mads Hansen    schedule 04.06.2010
comment
Почему я этого не осознавал? Огромное спасибо за то, что открыли мне слепой разум ;-) Хорошо: ссылка на AVT. - person Jan; 07.06.2010