2010-06-04 49 views
1

我的XSL源文件看起来像这样为什么撒克逊评估结果文档的URI是相同的?

<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> 

正如我的消息告诉我这似乎很好地工作 - 如果撒克逊不会评估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) 

有关如何解决此问题的任何想法?

回答

7

您指定一个变量$filename@file,但在{}所以它正在评估它作为字符串“$文件名”每次(这是相同的URI,因此错误)没有包裹。

您需要它评估为Attribute Value Template

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

为什么我没有意识到这一点?非常感谢你打开我的盲目头脑;-)好:参考AVT。 – Jan 2010-06-07 09:33:40