2010-06-04 7 views
1

내 XSL 소스 문서는 내가 기계 당 하나의 결과-문서를 만들려면이왜 Saxon은 결과 문서 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

당신은 @file에 대한 변수 $filename를 지정하고 있지만 {}은 그래서 문자열 "$ 파일 이름"(같은 URI, 따라서 오류가)마다로 평가하고있다으로 포장하지 않았다.

당신은 그것이 Attribute Value Template으로 평가해야합니다.

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

왜 내가 알지 못했습니까? 맹인 정신을 열어 주셔서 대단히 감사합니다 .-) 좋습니다 : AVT에 대한 참고서. – Jan