2016-10-03 15 views
0

Xpath 1.0과 XalanJ 2.7.1에서 xslt 1.0을 사용합니다. 템플릿을 프로파일 링하고 통화 시간을 줄이려고합니다. 그래서 가장 큰 핫스팟은 다음과 같습니다 :XSLT 1.0을 사용하는 템플릿의 xslt 처리 중 최적화?

<xsl:template name="tplAttribute"> 
    <xsl:param name="sourceObject" /> 
    <xsl:param name="sourceName" /> 
    <xsl:param name="targetName" /> 

    <xsl:variable name="sourceAttribute" select="$sourceObject/attribute[@name = $sourceName]" /> 
    <xsl:if test="$sourceAttribute"> 
     <dcx:attribute name="{$targetName}"> 
      <xsl:value-of select="$sourceAttribute" /> 
     </attribute> 
    </xsl:if> 
</xsl:template> 

871 히트 중 평균 시간은 103이고 변수는 59ms입니다.

변환 시간을 줄이기 위해 더 좋은 해결책이 있습니까?

object 
    tplAttribute 
    tplAttribute 
    tplAttributeDefault 
    tplAttribute 
    tplAttributeSomeDifferentLogic 
    tplAttribute 
    tplAttributeOther 

enter image description here

+0

일반적으로 얼마나 많은 "속성"요소가 $ sourceObject의 하위 항목으로 발견됩니까? –

+0

그러나 20에서 100까지 다릅니다. 따라서 $ sourceObject가 있고 여기에 특정 속성을 찾아야합니다. 하지만 우리는 다른 것을 찾아야합니다. 어떤 상황에서는 tplAttributeOther 등 다른 논리가 있습니다. 그래서 변수 생성이 느려지거나 프로세스가 느려지거나 sourceAttribute 대신에 두 개가 선택되면 var가 프로세서 최적화를 기반으로 더 빠릅니다. – Xelian

+0

나는 잘란의 내부를 모른다. Saxon-EE는 이것을 평가할 색인을 만들 것입니다. 시도를하고 결과를 알려주십시오. –

답변

0

핵심 <xsl:key name="att-by-name" match="attribute" use="@name"/>을 정의하고

<xsl:for-each select="$sourceObject"> 
    <xsl:if test="key('att-by-name', $sourceName)"> 
      <dcx:attribute name="{$targetName}"> 
       <xsl:value-of select="key('att-by-name', $sourceName)" /> 
      </attribute> 
    </xsl:if> 
</xsl:for-each> 

대신

사용

는 편집 : 프로세스의 sourceObject이 '때 입력 구조 템플릿 호출 16,

<xsl:variable name="sourceAttribute" select="$sourceObject/attribute[@name = $sourceName]" /> 
    <xsl:if test="$sourceAttribute"> 
     <dcx:attribute name="{$targetName}"> 
      <xsl:value-of select="$sourceAttribute" /> 
     </attribute> 
    </xsl:if> 
당신은 attribute 요소의 name 속성이 attribute 요소 (들)을 식별하는 경우, 그림과 같이 키 기반의 접근 방식은 당신이 전체 문서를 찾고 있습니다 작동합니다 우리에게 sourceObject와 문서의 정확한 구조를 표시해야 할 수도 있습니다

. 하위 트리 만보고있는 경우 키 값에 id를 포함해야 할 수도 있습니다.