2017-11-09 2 views
1

... 나는 XSLT에서 일부 제품의 수출을 쓰고 있어요 내가 중첩 된 종류/헤더 select 문 등을 감안할 때XSLT에서 큰 XPath를 어떻게 분류 할 수 있습니까?

의 이러한 종류가 나는, 일부 상당히 큰 선택 문이

/objects/object/items/item[ 
    not(
     custom_options/custom_option[bracelet_piece='engraving_style']/value = preceding::item[ 
      (
       custom_options/custom_option[bracelet_piece='engraving_style']/value = 'Black Engraving' 
       or custom_options/custom_option[bracelet_piece='engraving_style']/value = 'Laser Engraved' 
      ) 
      and not(product_type='configurable') 
      and (
       product_attributes/product_type='Dog Tag' 
       or product_attributes/product_type='Other Engraveable' 
      ) 
     ]/custom_options/custom_option[bracelet_piece='engraving_style']/value 
    ) 
    and (
     custom_options/custom_option[bracelet_piece='engraving_style']/value = 'Black Engraving' 
     or custom_options/custom_option[bracelet_piece='engraving_style']/value = 'Laser Engraved' 
    ) 
    and not(product_type='configurable') 
    and (product_attributes/product_type='Dog Tag' or product_attributes/product_type='Other Engraveable') 

구문의 섹션을 런타임에 평가할 재사용 가능한 문자열로 나눌 수 있습니까?

그것은 소리 나는 값 템플릿 속성 싶지만, 내가 그의 찾을 수있는 것은 그들이 가장 쉽고 위 밖으로 아마 덜 유용 예를 풀려면 선택 문

에서 사용할 수 없습니다 말한다 거의 것처럼, 매번 텍스트를 복사하지 않고 not(product_type='configurable')을 select 문에 포함 할 수 있기를 원한다고 가정 해 봅시다. 그렇게 할 수있는 방법이 있습니까?

참고 :이 섹션의 결과는 for-each 지시문에서 선택이므로 여기에 저장할 수 없습니다.

답변

2

속성 값 템플릿에 대해 언급 했으므로 select 속성에 대해 이야기하고 있다고 생각하면 XSLT 3 (올해 6 월 이후 W3C 권장)에서 배우고 Java, .NET에 대해서는 Saxon 9.8과 함께 사용할 수 있습니다. 및 C++/C 및 Altova XMLSPY/랩터 2017 또는 2018로 그렇게 shadow attributes (즉 _select 대신 select의)라고 사용할 수 있습니다 static variables or parameters

<xsl:variable name="exp1" as="xs:string" static="yes" select="&quot;not(product_type='configurable')&quot;"/> 

와 당신은 예를 사용할 수 있습니다

XSLT 2 및 3을 사용하여 고유 한 기능을 정의 할 수도 있습니다.

<xsl:function name="mf:exp1" as="xs:boolean"> 
    <xsl:param name="item"/> 
    <xsl:sequence select="not($item/product_type='configurable')"/> 
</xsl:function> 

다음

<xsl:for-each select="/objects/object/items/item[mf:exp1(.)]"> 

(즉 물론 접두사 mf 또는 당신이 당신의 기능, 예를 들어 xmlns:mf="http://example.com/mf"에 대한 네임 스페이스에 사용하려는 접두사 바인딩 필요)를 사용합니다.

+0

오! 물론 함수들. 그것은 뒷모습에서 꽤 명백하게 보인다. 감사! – Navarr

+0

업데이트 : XSL v1이 붙어있어서 기능이 제대로 작동하지 않습니다. 나는 막연한 한계 일 수도 있다고 생각한다. – Navarr

+0

일부 XSLT 1 프로세서는 XSLT 1에 대한 일부 확장을 지원하여 http://exslt.org/func/index.html 또는 일부 스크립팅 언어를 사용하는 확장 기능과 같은 기능을 정의하지만 주어진 XSLT 1과 XPath 1에서는 할 수있는 일이 많지 않습니다. 그래서 어떤 XSLT 1 프로세서를 목표로합니까? –

관련 문제