政策中引用的 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>
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-08-29。"],[[["\u003cp\u003eThe XSLTransform policy in Apigee and Apigee hybrid allows for the transformation of XML messages into other formats, such as HTML or plain text, using custom XSLT stylesheets.\u003c/p\u003e\n"],["\u003cp\u003eThis policy requires a named XSLT stylesheet stored in the API proxy's \u003ccode\u003e/resources/xsl\u003c/code\u003e directory and the XML message to be transformed, with optional parameters for specifying the output variable and matching stylesheet parameters.\u003c/p\u003e\n"],["\u003cp\u003eApigee's XSLT processing is powered by the Saxon XSLT processor, supporting XSLT 1.0 and 2.0, but it does not support the \u003ccode\u003e<xsl:include>\u003c/code\u003e and \u003ccode\u003e<xsl:import>\u003c/code\u003e elements, nor does it support XML external entities.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003eContent-Type\u003c/code\u003e header on the message to be transformed needs to be set to XML (e.g., \u003ccode\u003etext/xml\u003c/code\u003e or \u003ccode\u003eapplication/xml\u003c/code\u003e) for the transformation to occur, and the \u003ccode\u003e<Source>\u003c/code\u003e element needs to be set correctly based on whether the source XML is in the request or response.\u003c/p\u003e\n"],["\u003cp\u003eThe XSLTransform policy has runtime and deployment errors, such as \u003ccode\u003esteps.xsl.XSLSourceMessageNotAvailable\u003c/code\u003e if the source message is unavailable and \u003ccode\u003eXSLEmptyResourceUrl\u003c/code\u003e if the \u003ccode\u003e<ResourceURL>\u003c/code\u003e is empty, and may have cost or utilization implications depending on your Apigee license.\u003c/p\u003e\n"]]],[],null,["# XSLTransform policy\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\n### What\n\nThe XSLTransform policy applies custom [Extensible\nstylesheet language transformations (XSLT)](https://en.wikipedia.org/wiki/XSLT) to\nXML messages, letting you transform them from XML to another format, such as HTML or plain\ntext. The policy is often used to integrate applications that support XML, but that require\ndifferent XML-based formats for the same data.\n\nThis policy is an *Extensible policy* and use of this policy might have cost or\nutilization implications, depending on your Apigee license. For information on policy types\nand usage implications, see\n[Policy types](/apigee/docs/api-platform/reference/policies/reference-overview-policy#policy-types).\n| **Note:** This policy transforms XML only if the `Content-Type` header on the message to be transformed is set to XML. For example, `text/xml` or `application/xml`.\n| **Note:**The XSL Transform policy does not support reading, loading, or manipulating XML external entities (XXEs).\n\n### Inputs\n\nThe XSL policy takes the following inputs:\n\n- **(Required)** The name of an XSLT stylesheet, which contains a set of transformation rules stored in the API proxy under `/resources/xsl`.\n- **(Required)** The XML to be transformed (typically a request or response message).\n- (Optional) The name of a variable that stores the output.\n- (Optional) Parameters that match parameters in the XSL stylesheet.\n\n### Parsing processor\n\nApigee relies on the [Saxon XSLT\nprocessor](https://saxon.sourceforge.net/), and supports XSLT 1.0 and 2.0.\n\n### Unsupported XSL elements\n\nThe XSL policy does not support the following XSL elements:\n\n- `\u003cxsl:include\u003e`\n- `\u003cxsl:import\u003e`\n\n### Samples\n\nThe following samples show an XSL transformation flow: \n\n### XSL policy --\\\u003e\n\n```scdoc\n\u003cXSL name=\"TransformXML\"\u003e\n \u003cResourceURL\u003exsl://my_transform.xsl\u003c/ResourceURL\u003e\n \u003cSource\u003erequest\u003c/Source\u003e\n\u003c/XSL\u003e\n```\n\nSimple XSL policy. Go to the next example to see the XSLT stylesheet referenced in the\npolicy (`my_transform.xsl`). The [`\u003cSource\u003e`](/apigee/docs/api-platform/reference/policies/xsl-transform-policy#source) element is important.\nFor example, if the XML you want to transform is in the response, the transformation won't\noccur unless you set the `\u003cSource\u003e` to `response` (and the policy is attached to\nthe response flow). But in this case, the XML to be transformed is in the request.\n\n### XSLT stylesheet --\\\u003e\n\n```actionscript-3\n\u003cxsl:stylesheet xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" version=\"1.0\"\u003e\n \u003cxsl:output method=\"text\"/\u003e\n \u003cxsl:variable name=\"newline\"\u003e\n \u003cxsl:text\u003e\u003c/xsl:text\u003e\n \u003c/xsl:variable\u003e\n \u003cxsl:template match=\"/\"\u003e\n \u003cxsl:text\u003e<Life>\u003c/xsl:text\u003e\n \u003cxsl:value-of select=\"$newline\"/\u003e\n \u003cxsl:text\u003eHere are the odd-numbered items from the list:\u003c/xsl:text\u003e\n \u003cxsl:value-of select=\"$newline\"/\u003e\n \u003cxsl:for-each select=\"list/listitem\"\u003e\n \u003cxsl:if test=\"(position() mod 2) = 1\"\u003e\n \u003cxsl:number format=\"1. \"/\u003e\n \u003cxsl:value-of select=\".\"/\u003e\n \u003cxsl:value-of select=\"$newline\"/\u003e\n \u003c/xsl:if\u003e\n \u003c/xsl:for-each\u003e\n \u003cxsl:text\u003e</Life>\u003c/xsl:text\u003e\n\u003c/xsl:template\u003e\n\u003c/xsl:stylesheet\u003e\n```\n\nThe `my_transform.xsl` stylesheet referenced in the policy. Go to the next\nsample to see an example of an incoming XML message.\n\n### Message --\\\u003e\n\n```text\n\u003c?xml version=\"1.0\"?\u003e\n\u003clist\u003e\n \u003ctitle\u003eA few of my favorite albums\u003c/title\u003e\n \u003clistitem\u003eA Love Supreme\u003c/listitem\u003e\n \u003clistitem\u003eBeat Crazy\u003c/listitem\u003e\n \u003clistitem\u003eHere Come the Warm Jets\u003c/listitem\u003e\n \u003clistitem\u003eKind of Blue\u003c/listitem\u003e\n \u003clistitem\u003eLondon Calling\u003c/listitem\u003e\n \u003clistitem\u003eRemain in Light\u003c/listitem\u003e\n \u003clistitem\u003eThe Joshua Tree\u003c/listitem\u003e\n \u003clistitem\u003eThe Indestructible Beat of Soweto\u003c/listitem\u003e\n\u003c/list\u003e\n```\n\nSample message in the request (indicated in the policy's\n`\u003cSource\u003erequest\u003c/Source\u003e` element in the first sample).\n\n### Transformed message\n\n```text\n\u003cLife\u003e\nHere are the odd-numbered items from the list:\n1. A Love Supreme\n3. Here Come the Warm Jets\n5. London Calling\n7. The Joshua Tree\n\u003c/Life\u003e\n```\n\nThe transformed message after the XSLT stylesheet from these samples is applied to the XML\nmessage.\n\n`\u003cXSL\u003e` element\n---------------\n\nDefines an `XSLTransform` policy.\n\n| **Note:** `\u003cxsl:include\u003e` and `\u003cxsl:import\u003e` are not supported.\n\nThe `\u003cXSL\u003e` element has the following attributes:\n\nChild element reference\n-----------------------\n\nThis section describes the child elements of [`\u003cXSL\u003e`](/apigee/docs/api-platform/reference/policies/xsl-transform-policy#xsl).\n\n### `\u003cOutputVariable\u003e`\n\nA variable that stores the output of the transformation. You should\nset this element to be a custom variable, and then consume that variable.\n\nThe value of `\u003cOutputVariable\u003e` cannot be a *message* type; that is, it cannot be\n`message`, `request`, or `response`.\n\nTo replace the message content with the output of the transformation, delete this\nelement. For example, if you're transforming a message to HTML, don't include this\nelement.\n\n### `\u003cParameters\u003e`\n\nAdds support for the `\u003cxsl:param\u003e` element in your stylesheets. You define\neach parameter as a [`\u003cParameter\u003e`](/apigee/docs/api-platform/reference/policies/xsl-transform-policy#parameter) child element of this element.\n\nThe `\u003cParameters\u003e` element has the following attributes:\n\n#### `\u003cParameter\u003e`\n\nDefines a parameter in the [`\u003cParameters\u003e`](/apigee/docs/api-platform/reference/policies/xsl-transform-policy#parameters) element.\n\nThe `\u003cParameter\u003e` element has the following attributes:\n\nThe parameter gets its value either from the `ref` attribute or with an explicit\n`value`.\n\nFor an example and more information, see\n[How\nshould the optional parameters on the XSL Transform policy be used?](https://community.apigee.com/questions/1860/how-should-the-the-optional-parameters-on-the-xsl.html#answer-1864).\n\n### `\u003cResourceURL\u003e`\n\nThe XSL file that Apigee uses for transforming the message. The value of this element is the\nname of the XSL stylesheet stored in the API proxy under `/resources/xsl`.\n\nFor example: \n\n```text\n\u003cResourceURL\u003exsl://SubscriberNumbers-Request.xsl\u003c/ResourceURL\u003e\n```\n\nFor more information, see [resource files](/apigee/docs/api-platform/develop/resource-files).\n\n### `\u003cSource\u003e`\n\nSpecifies the message that is transformed. Usually this value is\nset to `request` or `response`, depending on whether the message to\nbe transformed is inbound or outbound.\n\nThe XSL file that defines the transformation is defined by the [`\u003cResourceURL\u003e`](/apigee/docs/api-platform/reference/policies/xsl-transform-policy#resourceurl).\n\n- If the source is missing, it is treated as a simple message. For example, `\u003cSource\u003emessage\u003c/Source\u003e`\n- If the source variable cannot be resolved, or resolves to a non-message type, the transformation step fails.\n\n| **Sample:** See our [GitHub\n| repository](https://github.com/apigee/api-platform-samples/tree/master/schemas/policy) samples for the most recent schemas.\n\nError reference\n---------------\n\n\n### Runtime errors\n\nThese errors can occur when the policy executes.\n\n### Deployment errors\n\nThese errors can occur when you deploy a proxy containing this policy.\n| Need help resolving an error? Click *build* next to the error's cause description to visit the troubleshooting page.\n\n\u003cbr /\u003e\n\nRelated topics\n--------------\n\n| - [jira-release-notes](https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/jira-release-notes)\n| - [pagination](https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/pagination)\n| - [soap](https://github.com/apigee/api-platform-samples/tree/master/sample-proxies/soap)"]]