2015-02-03 3 views
0

XSL 2.0에 다음 코드가 있습니다. 그러나 환경에 의해 부과 된 제한 때문에 XSL 버전 1.0으로 되돌려 야합니다. XSL 1.0에서는 함수가 허용되지 않기 때문에 1.0에서 어떻게 할 것인가?XSLT 1.0 - 함수 대신

<!-- a custom 'contains' implementation --> 
<xsl:function name="my:contains" as="xs:boolean"> 
    <xsl:param name="str" as="xs:string" /> 
    <xsl:param name="list" as="xs:string+" /> 
    <xsl:variable name="temp" as="xs:boolean*"> 
    <xsl:for-each select="$list"> 
     <xsl:if test="contains($str, .)"> 
     <xsl:sequence select="xs:boolean('true')" /> 
     </xsl:if> 
    </xsl:for-each> 
    </xsl:variable> 
    <xsl:sequence select="if ($temp[1] = xs:boolean('true')) then xs:boolean('true') else xs:boolean('false')" /> 
</xsl:function>  

    <xsl:param      name = "excludedSections" 
           select = "('AboutThis','79','GetMore')"/> 


**Being used as** 



    <xsl:if test = "(not(my:contains($sectionId, $excludedSections)) 
               and 
               (contains(
               concat(' ', @IncludedDevices, ' '), 
               concat(' ', $targetedDevice, ' ') 
               ) `enter code here` 
               or 
               not(@IncludedDevices) 
              ) 
               and 
               (not(contains(
               concat(' ', @ExcludedDevices, ' '), 
               concat(' ', $targetedDevice, ' ') 
               )) 
               or 
               not(@ExcludedDevices) 
              ))"> 
      .......Do something.... 
    </xsl:if> 

감사합니다, GP는

+0

당신이 주어진 코드의 검토를 찾고 있다면 당신은 http://codereview.stackexchange.com/을 고려할 수 있습니다 단순화 할 수있다. –

+1

@StephenReindl 이것은 코드 리뷰 –

+0

@GP_help에 속하지 않는 **에서 ** 현재 코드를 2.0에서 1.0으로 "번역"하는 것입니다. 귀하의 의견이 내 답변을 나타낼 경우 귀하의 질문이 대답했다. –

답변

1

그럼 당신은 XSLT 1.0 코드의 호출 블록을 구현하기 위해 명명 된 템플릿을 작성할 수 있습니다. 그러나 단순히 목록에 첫 번째 인수에 포함 된 문자열이 포함되어 있는지 확인하려는 것 같습니다. 따라서 exsl:node-set (정의 xmlns:exsl="http://exslt.org/common")을 사용하면 목록을 결과 트리 조각으로 정의하고이를 노드 집합으로 변환합니다.

<xsl:param name="excludedSectionsRtf"> 
    <item>AboutThis</item> 
    <item>79</item> 
    <item>GetMore</item> 
</xsl:param> 

<xsl:variable name="excludedSections" select="exsl:node-set($excludedSectionsRtf)/item"/> 

다음으로 기본적으로 포함 된 항목이 $sectionId인지 확인하는 포함 체크가 <xsl:if test="not($excludedSections[contains($sectionId, .)])">...</xsl:if>이됩니다. 당신의 XSLT 2.0 기능을 가정

<xsl:function name="my:contains" as="xs:boolean"> 
    <xsl:param name="str" as="xs:string" /> 
    <xsl:param name="list" as="xs:string+" /> 
    <xsl:sequence select="some $s in $list satisfies contains($str, $s)"/> 
</xsl:function>