2014-09-14 3 views
0

XSLT 3.0 here에 대한 W3C 설명서를 읽었습니다. 다음은 내가 가지고있는 것입니다.XSLT에서지도를 사용하는 방법은 무엇입니까?

<xsl:stylesheet version="3.0" 
       xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:variable name="week" as="map(xs:string, xs:string)"> 
     <xsl:map> 
     <xsl:map-entry key="'Mo'" select="'Monday'"/> 
     <xsl:map-entry key="'Tu'" select="'Tuesday'"/> 
     <xsl:map-entry key="'We'" select="'Wednesday'"/> 
     <xsl:map-entry key="'Th'" select="'Thursday'"/> 
     <xsl:map-entry key="'Fr'" select="'Friday'"/> 
     <xsl:map-entry key="'Sa'" select="'Saturday'"/> 
     <xsl:map-entry key="'Su'" select="'Sunday'"/> 
     </xsl:map> 
    </xsl:variable> 
</xsl:stylesheet> 

지도를 만든 후에는 값을 어떻게 사용하고 검색합니까? 이전 버전의 XSLT에서지도를 만드는 다른 방법이 있습니까?

답변

1

이 @Cajetan_Rodrigues의 대답에 추가하려면, XSLT 2.0에서 가장 가까운 해당하는이 같은 임시 트리를 만들 아마이었다 임시 XML 트리를 통한지도의 좌표는 다음과 같습니다.

  • 항목은 XML 요소 및 attr ibutes. 예를 들어, 항목, 정수의 순서, 또는 추가 또는 임시 XML 트리를 수정하는 것보다 훨씬 더 효율적으로 될 수있는 항목을 삭제하여지도를 수정 외부 XML 요소

  • 참조 수 있습니다지도 때문에 노드 ID, 문서 순서, 네임 스페이스, 선행/차후/상위 탐색 등과 같은 개념을 지원할 필요가 없습니다.

+0

그래서이 값을 검색합니까? $ week ('Mo') –

+0

예. (..............) –

1

언급 한 링크도 우수합니다. examples. 값의 사용 및 검색을 위해 참조 할 수 있습니다.

이전 버전의 XSLT에 대해서는 기능상 유사한 구조가 map에 없었습니다. 나중에 검색 할 값이 필요한 경우 가장 좋은 방법은 변수를 다른 변수에 저장하는 것입니다. 즉, 정확하게 이유 why the map structure was introduced입니다 :

<xsl:variable name="week" as="map(xs:string, xs:string)"> 
     <map> 
     <entry key="Mo" value="Monday"/> 
     <entry key="Tu" value="Tuesday"/> 
     <entry key="We" value="Wednesday"/> 
     <entry key="Th" value="Thursday"/> 
     <entry key="Fr" value="Friday"/> 
     <entry key="Sa" value="Saturday"/> 
     <entry key="Su" value="Sunday"/> 
     </map> 
    </xsl:variable> 

장점 :

Maps have many uses, but their introduction to XSLT 3.0 was strongly motivated by streaming use cases. In essence, when a source document is processed in streaming mode, data that is encountered in the course of processing may need to be retained in variables for subsequent use, because the nodes cannot be revisited. This creates a need for a flexible data structure to accommodate such temporary data, and maps were designed to fulfil this need.