XSLTransform 정책

<ph type="x-smartling-placeholder"></ph> 현재 Apigee Edge 문서를 보고 있습니다.
Apigee X 문서.
정보

대상

XSL Transform 정책은 커스텀 확장 가능한 스타일시트 언어 변환(XSLT)을 XML 메시지에 적용하여 XML에서 XML, HTML, 또는 일반 텍스트와 같은 다른 형식으로 변환할 수 있도록 합니다. 이 정책은 XML을 지원하지만 동일한 데이터에 대해 다른 XML 형식이 필요한 애플리케이션을 통합하는 데 주로 사용됩니다.

샘플

다음 샘플은 XSL 변환 흐름의 모든 리소스를 보여줍니다.

XSL 정책 ->

<XSL name="TransformXML">
  <ResourceURL>xsl://my_transform.xsl</ResourceURL>
  <Source>request</Source>
</XSL>

간단한 XSL 정책입니다. 다음 예시로 이동하여 정책(my_transform.xsl)에서 참조된 XSLT 스타일시트를 확인합니다. <Source> 요소가 중요합니다. 예를 들어 변환하려는 XML이 응답에 있는 경우 소스를 response로 설정하고 정책이 응답 흐름에 연결되지 않는 한 변환이 발생하지 않습니다. 하지만 이 경우에는 변환할 XML이 요청에 포함됩니다.

XSLT 스타일시트 ->

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  <xsl:output method="text"/>
  <xsl:variable name="newline">
  <xsl:text>
  </xsl:text>
  </xsl:variable>
  <xsl:template match="/">
  <xsl:text>&lt;Life&gt;</xsl:text>
    <xsl:value-of select="$newline"/>
    <xsl:text>Here are the odd-numbered items from the list:</xsl:text>
    <xsl:value-of select="$newline"/>
    <xsl:for-each select="list/listitem">
      <xsl:if test="(position() mod 2) = 1">
        <xsl:number format="1. "/>
        <xsl:value-of select="."/>
        <xsl:value-of select="$newline"/>
      </xsl:if>
    </xsl:for-each>
  <xsl:text>&lt;/Life&gt;</xsl:text>
</xsl:template>
</xsl:stylesheet>

정책에서 참조되는 my_transform.xsl 스타일시트입니다. 수신 XML 메시지의 예시를 보려면 다음 샘플로 이동하세요.

메시지 ->

<?xml version="1.0"?>
<list>
  <title>A few of my favorite albums</title>
  <listitem>A Love Supreme</listitem>
  <listitem>Beat Crazy</listitem>
  <listitem>Here Come the Warm Jets</listitem>
  <listitem>Kind of Blue</listitem>
  <listitem>London Calling</listitem>
  <listitem>Remain in Light</listitem>
  <listitem>The Joshua Tree</listitem>
  <listitem>The Indestructible Beat of Soweto</listitem>
</list>

요청의 샘플 메시지(첫 번째 샘플에서 정책의 <Source>request</Source> 요소에 표시됨)

변환된 메시지

<Life>
Here are the odd-numbered items from the list:
1. A Love Supreme
3. Here Come the Warm Jets
5. London Calling
7. The Joshua Tree
</Life>

이 샘플의 XSLT 스타일시트 이후에 변환된 메시지는 XML 메시지에 적용됩니다.


요소 참조

다음 요소를 사용하여 XSL Transformation 정책을 구성합니다.

필드 이름 설명
이름(필수) 정책의 이름입니다. 이름에 사용할 수 있는 문자는 A-Z0-9._\-$ %로 제한됩니다. 하지만 관리 UI는 추가 제한사항이 적용됩니다. 영숫자가 아닌 문자를 자동으로 삭제하는 등의 작업을 예로 들 수 있습니다
소스(선택사항) 정보를 추출해야 하는 메시지를 포함합니다. 이 값은 변환할 메시지가 인바운드 또는 아웃바운드인지에 따라 request 또는 response로 설정됩니다.
  • 소스가 누락된 경우 간단한 메시지로 처리됩니다. 예: <Source>message</Source>
  • 소스 변수를 확인할 수 없거나 메시지 유형이 아닌 것으로 확인되면 변환 단계가 실패합니다.
OutputVariable(선택사항)

변환의 출력을 저장하는 변수입니다. OutputVariable은 메시지 유형, 즉 'message', 'request' 또는 'response'가 될 수 없습니다. 이 요소를 커스텀 변수로 설정한 다음 해당 변수를 사용합니다.

메시지 콘텐츠를 변환 출력으로 바꾸려면 이 요소를 삭제합니다. 예를 들어 메시지를 HTML로 변환하는 경우 이 요소를 포함하지 마세요.

ResourceURL(필수) 메시지 변환에 사용할 XSLT 파일입니다.
매개변수(선택사항) ignoreUnresolvedVariables(선택사항)
XSLT 스크립트 안내에서 확인되지 않은 변수 오류는 무시합니다.
유효한 값: true/false
기본값: false
매개변수(선택사항) name(필수)

매개변수는 스타일시트에서 XSL 매개변수 사용을 지원합니다. 여기서 정책에 추가하는 이름은 XSL 매개변수의 이름입니다. 예를 들어 'uid'라는 이름을 입력하면 XSL은 다음과 같이 표시됩니다. <xsl:param name="uid" select="''"/>

매개변수는 컨텍스트 변수(ref 속성으로 식별됨)에 대한 참조 또는 명시적 value에서 값을 가져옵니다.

예시 및 자세한 내용은 http://community.apigee.com/questions/1860/how-should-the-the-optional-parameters-on-the-xsl.html#answer-1864를 참조하세요.

ref(선택사항)

변수의 값을 가져오는 참조를 지정합니다. 예를 들어 'uid' 매개변수가 'authn.uid'라는 변수에서 값을 가져와야 하는 경우 매개변수 요소는 다음과 같이 표시됩니다. <Parameter name="uid" ref="authn.uid"/>

이 속성을 사용하는 경우 값 속성을 사용하지 마세요.

value(선택사항)

이 속성을 사용하여 매개변수 값을 하드 코딩할 수 있습니다.

이 속성을 사용하는 경우 ref 속성을 사용하지 마세요.


사용 참고사항

XSLT는 독립 실행형 .xsl 파일로 구현됩니다. 이 파일은 /resources/xsl의 API 프록시에 저장됩니다. XSL 정책은 XSL 파일을 단순히 참조만 합니다. 자세한 내용은 리소스 파일을 참조하세요.

XSL 정책에는 다음 두 가지 입력을 요구합니다.

  • /resources/xsl의 API 프록시에 저장된 XSLT 스타일시트의 이름(일련의 변환 규칙이 포함됨)
  • 변환할 XML 소스(일반적으로 요청 또는 응답 메시지)

<xsl:include><xsl:import>는 지원되지 않습니다.

Apigee Edge는 Saxon XSLT에서 프로세서를 포함하며 XSLT 1.0 및 2.0을 지원합니다.


오류 참조

Runtime errors

These errors can occur when the policy executes.

Fault code HTTP status Cause Fix
steps.xsl.XSLSourceMessageNotAvailable 500 This error occurs if the message or string variable specified in the <Source> element of the XSL Transform policy is either out of scope (not available in the specific flow where the policy is being executed) or can't be resolved (is not defined).
steps.xsl.XSLEvaluationFailed 500 This error occurs if the input XML payload is unavailable/malformed or the XSLTransform policy fails/is unable to transform the input XML file based on the transformation rules provided in the XSL file. There could be many different causes for the XSLTransform policy to fail. The reason for failure in the error message will provide more information on the cause.

Deployment errors

These errors can occur when you deploy a proxy containing this policy.

Error name Cause Fix
XSLEmptyResourceUrl If the <ResourceURL> element in the XSL Transform policy is empty, then the deployment of the API proxy fails.
XSLInvalidResourceType If the resource type specified in the <ResourceURL> element of the XSL Transform policy is not of type xsl, then the deployment of the API proxy fails.

관련 주제