2013-03-26 1 views
0
<xsl:choose> 
    <xsl:when test="type='LEVEL'"> 
    <xsl:variable name="myVar" select = "value"/> 
     <xsl:variable name="spaces" select = "'&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0'"/> 
     <xsl:value-of select="substring($spaces, 1, $myVar)"/> 
    </xsl:when> 

위 코드는 XSLT에 있습니다. myVar는 (1 또는 2 또는 3)과 같은 값을 갖는 변수입니다. 변수에 다음 코드 행의 출력을 저장하고 when 조건 외부에서 사용해야합니다.변수에 값 넣기 및 XSLT에서 사용하기

xsl:value-of select="substring($spaces, 1, $myVar)"/ 

현재 진행할 수 없습니다. 누구든지 뭔가 제안 할 수 있습니까?

답변

0

내가 무엇을 하려는지 확실하지 않지만 다음을 시도해 볼 수 있습니다. 소스 XML : 그것은 당신이 출력을 제공

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
version="1.0"> 


<xsl:template match="itemProperties"> 
    <xsl:variable name="fromOutputTemplate"> 
     <xsl:call-template name="output"/> 
    </xsl:variable> 
    <out> 
     <xsl:value-of select="$fromOutputTemplate"/>  
    </out>   
</xsl:template> 

<xsl:template name="output"> 
    <xsl:variable name="spaces" select = "'&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;'"/> 
    <xsl:variable name="myVar" select = "value"/> 

    <xsl:choose> 
     <xsl:when test="type='LEVEL'"> 
       <xsl:value-of select="substring($spaces, 1, $myVar)"/> 
     </xsl:when> 
    </xsl:choose> 
</xsl:template> 


</xsl:stylesheet> 

:

<?xml version="1.0" encoding="UTF-8" standalone="yes" ?> 
<Result> 
<resultDetails> 
    <resultDetailsData> 
     <itemProperties> 
      <ID>1</ID> 
      <type>LEVEL</type> 
      <value xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema" xsi:type="xs:int">5</value> 
     </itemProperties> 
    </resultDetailsData> 
</resultDetails> 
</Result> 

이 XSLT를 적용

<?xml version="1.0" encoding="UTF-8"?> 


     <out>     </out> 

이 방법은 당신이 가고 싶은 것이인가요?

감사합니다. Peter

0

수 없습니다. 변수가 when 조건 외부에 선언 될 수 있습니다 (선언에있는 일부 XPath가 실패하고 null을 반환하더라도). 또는 when 조건 내에 출력을 사용하십시오. 하지만 어쨌든 출력을 사용하고 싶다면 choose를 사용하는 이유는 무엇입니까? 그 후

<!-- You declare the 'tool' variables alone --> 
<xsl:variable name="myVar" select = "value"/> 
<xsl:variable name="spaces" select = "'&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0'"/> 

<!-- For myVarSub you use a sequence constructor instead of the select way --> 
<xsl:variable name="myVarSub">  
    <xsl:choose> 
     <xsl:when test="type='LEVEL'">  
      <!-- xsl:sequence create xml node --> 
      <xsl:sequence select="substring($spaces, 1, $myVar)"/> 
     </xsl:when> 
    <xsl:choose> 
</xsl:variable> 

, 단지 출력을 또는 필요에 변수를 사용 마지막 시도, 다음과 같이 뭔가를 변수를 선언하고이 순서 생성자 내에서 선택 사용할 수 있습니다. 다른 조건을 추가하지 않으면 테스트가 false 일 때 myVar이 null이됩니다. 그러나 xsl : sequence 때문에 xslt 2.0 솔루션이라는 점에 유의하십시오.