2017-12-21 16 views
1

주어진 파일의 루트 폴더 경로를 추출하려면 어떻게해야합니까?XSLT 절대 경로에서 상대 경로

나는 표현

path/to/one/of/my/file.xml 

내가 XSLT/XPath를 사용하여

../../../../../ 

을 받아야합니다 있나요? fn:tokenize이는 XPath 2.0 기능이기 때문에

+0

슬래시의 수는 알 수없는 내가 XSLT 1.0을 사용하고 있습니다 –

+0

경로가'path/to/one/of/my/file.xml' 인 경우'path'를 원하십니까? –

+0

당신이 원하는 상대 경로는'../../../../'아닙니다 .. ../../../../../'- 당신이나 내가 오프 바이 한 오류. –

답변

0

, 당신은 재귀 템플릿을 사용할 수 있습니다

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
<xsl:output method="text" /> 

    <xsl:template match="/"> 
    <!-- initial call with path to tokenize --> 
    <xsl:call-template name="tokenize"> 
     <xsl:with-param name="str" select="'path/to/one/of/my/file.xml'" /> 
    </xsl:call-template>  
    </xsl:template> 

    <!-- recursive named template -->  
    <xsl:template name="tokenize"> 
    <xsl:param name="str" /> 
    <xsl:param name="result" select="''" /> 
    <xsl:choose> 
     <xsl:when test="substring-after($str,'/')"> 
     <xsl:call-template name="tokenize"> 
      <xsl:with-param name="str" select="substring-after($str,'/')" /> 
      <xsl:with-param name="result" select="concat($result,'../')" /> 
     </xsl:call-template> 
     </xsl:when> 
     <xsl:otherwise> 
     <xsl:value-of select="$result" /> 
     </xsl:otherwise> 
    </xsl:choose> 
    </xsl:template> 

</xsl:stylesheet> 

출력 :

../../../../../