您目前查看的是 Apigee 和 Apigee Hybrid 說明文件。
查看
Apigee Edge 說明文件。
XSLSourceMessageNotAvailable
錯誤代碼
steps.xsl.XSLSourceMessageNotAvailable
錯誤回應主體
{
"fault": {
"faultstring": "response message is not available for XSL: policy_name",
"detail": {
"errorcode": "steps.xsl.XSLSourceMessageNotAvailable"
}
}
}錯誤訊息範例
{
"fault": {
"faultstring": "response message is not available for XSL: xslt",
"detail": {
"errorcode": "steps.xsl.XSLSourceMessageNotAvailable"
}
}
}
原因
如果 XSLTransform 政策的 <Source> 元素中指定的 message 或字串變數符合下列任一條件,就會發生這個錯誤:
- 超出範圍 (無法在執行政策的特定流程中使用)
- 無法解析 (未定義)
舉例來說,如果 XSLTransform 政策應在要求流程中執行,但 <Source> 元素設為回應變數,而要求流程中沒有這個變數,就會發生這項錯誤。
診斷
找出發生錯誤的 XSLTransform 政策,以及無法使用的變數名稱。您可以在錯誤回應的
faultstring元素中找到這兩項資訊。舉例來說,在下列faultstring中,政策名稱為xslt,變數為response:faultstring": "response message is not available for XSL: xslt在失敗的 XSLTransform 政策 XML 中,確認
<Source>元素中設定的變數名稱,與錯誤字串中識別的變數名稱相符 (如上方的步驟 1)。舉例來說,下列 XSLTransform 政策會在<Source>元素中指定名為response的變數,該變數與錯誤字串中的內容相符:<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <XSL async="false" continueOnError="false" enabled="true" name="xslt"> <DisplayName>xslt</DisplayName> <Properties/> <ResourceURL>xsl://XSL-Transform.xsl</ResourceURL> <Source>response</Source> <Parameters ignoreUnresolvedVariables="false"/> <OutputVariable/> </XSL>判斷
<Source>元素中使用的變數是否已定義,且可在執行 XSLTransform 政策的流程中使用。如果變數為下列任一值:
- 超出範圍 (無法在執行政策的特定流程中使用),或
- 無法解析 (未定義)
這就是錯誤原因。
舉例來說,假設上述 XSLTransform 政策應在要求流程中執行。回想一下,範例政策的
<Source>元素中使用了response變數。response變數只能在回覆流程中使用。由於要求流程中沒有
response變數,因此您會收到下列錯誤代碼:steps.xsl.XSLSourceMessageNotAvailable
解析度
請確認在失敗的 XSLTransform 政策的 <Source> 元素中設定的變數,已在政策執行的流程中定義並存在。
如要修正上述範例 XSLTransform 政策,可以修改 <Source> 元素,使用 request 變數,因為該變數存在於要求流程中:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="xslt">
<DisplayName>xslt</DisplayName>
<Properties/>
<ResourceURL>xsl://XSL-Transform.xsl</ResourceURL>
<Source>request</Source>
<Parameters ignoreUnresolvedVariables="false"/>
<OutputVariable/>
</XSL>
XSLEvaluationFailed
錯誤代碼
steps.xsl.XSLEvaluationFailed
錯誤回應主體
{
"fault": {
"faultstring": "Evaluation of XSL <var>XSL_file_name</var> failed with reason: \"<var>reason_for_failure</var>",
"detail": {
"errorcode": "steps.xsl.XSLEvaluationFailed"
}
}
}
錯誤訊息範例
{
"fault": {
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Premature end of document while parsing at line 1(possibly around char 0)\"",
"detail": {
"errorcode": "steps.xsl.XSLEvaluationFailed"
}
}
}
可能原因
發生這個錯誤的可能原因如下:
- 輸入的 XML 酬載無法使用/格式錯誤。
- XSLTransform 政策失敗/無法根據 XSL 檔案中提供的轉換規則,轉換輸入的 XML 檔案。XSLTransform 政策失敗的原因有很多種。錯誤訊息中的失敗原因會提供更多資訊,說明失敗原因。下表列出其中一個導致這項失敗的原因 (前置字串無效),並附上範例說明。
| 原因 | 說明 |
|---|---|
| 無法使用輸入 XML 酬載 | 未傳遞或空白的輸入 XML 酬載。 |
| 輸入的 XML 格式有誤 | 輸入的 XML 酬載格式錯誤或無效。 |
| 無效前置字元 | 輸入的 XML 酬載含有 XSL 檔案中未定義的前置字元。 |
原因:無法使用輸入 XML 酬載
如果未傳遞輸入 XML 酬載,或傳遞至具有 XSLTransform 政策的 API Proxy 的 API 要求中包含的 XML 酬載為空白,就會發生這個錯誤。
錯誤訊息範例
{
"fault": {
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Premature end of document while parsing at line 1(possibly around char 0)\"",
"detail": {
"errorcode": "steps.xsl.XSLEvaluationFailed"
}
}
}
診斷
找出 XML 轉換政策無法評估的 XSL 檔案,以及失敗原因。如果未傳遞輸入 XML 酬載或酬載為空白,失敗原因會指出剖析時文件過早結束。您可以在錯誤回應的
faultstring元素中找到所有這類資訊。舉例來說,在下列faultstring中,XSL 檔案為XSL-Transform.xsl,失敗原因是Premature end of document while parsing at line 1 (possibly around char 0)。這項錯誤表示系統未傳遞 XML 酬載,或酬載為空白。"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Premature end of document while parsing at line 1(possibly around char 0)\""判斷做為要求一部分傳遞的輸入 XML 酬載是否為空。如果未傳遞或傳遞的輸入內容為空白,就會導致錯誤。
在下列範例要求中,使用者傳送的要求酬載 (即要求主體) 為空。
例如:
curl -v "http://your_host_alias/v1/xsltransform" -H "Content-Type: application/xml"
其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的
virtualhosts.hostAliases屬性中設定。請參閱「指定設定覆寫」。由於 XML 輸入內容為空,您會收到以下錯誤訊息:
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Premature end of document while parsing at line 1(possibly around char 0)\""
解析度
請確認傳遞至 XSLTransform 政策的輸入內容是有效的 XML 酬載,且不為空白。
如要修正範例 XSLTransform 政策的問題,請傳遞有效的 XML 酬載。 例如:
建立名為
city.xml的檔案,並在當中加入下列內容:<?xml version="1.0" encoding="UTF-8"?> <root> <City>Bengaluru</City> <Name>Apigee</Name> <Pincode>560016</Pincode> </root>使用下列 curl 指令發出 API 呼叫:
curl -v "http://your_host_alias/v1/xsltransform" -H "Content-Type: application/xml" -X POST -d @city.xml
其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的
virtualhosts.hostAliases屬性中設定。請參閱「指定設定覆寫」。
原因:輸入的 XML 格式錯誤
傳遞至 XSLTransform 政策的 API 要求中,輸入的 XML 酬載格式錯誤或無效。
錯誤訊息範例
{
"fault": {
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unexpected char while looking for open tag ('<') character\"",
"detail": {
"errorcode": "steps.xsl.XSLEvaluationFailed"
}
}
}
診斷
找出 XML 轉換政策無法評估的 XSL 檔案,以及失敗原因。如果輸入的 XML 酬載格式錯誤,失敗原因會指出有非預期的字元。您可以在錯誤回應的
faultstring元素中找到所有這類資訊。舉例來說,在下列faultstring中,XSL 檔案為XSL-Transform.xsl,失敗原因是Unexpected char while looking for open tag ('<') character。也就是說,XML 酬載中缺少「<」。"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unexpected char while looking for open tag ('<') character\""檢查傳遞至 XSLTransform 政策的輸入 XML 酬載,看看是否含有有效的 XML 內容。如果輸入的酬載不是有效的 XML,就會導致錯誤。
在下列要求範例中,使用者傳送的輸入內容 (即要求主體) 無效。
例如:
curl -v "http://your_host_alias/v1/xsltransform" -H "Content-Type: application/xml" -X POST -d @city.xml
其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的
virtualhosts.hostAliases屬性中設定。請參閱「指定設定覆寫」。在本範例中,
city.xml定義為:{ "City": "Bengaluru", "Name": "Apigee", "Pincode": "560016" }由於輸入的酬載是 JSON,而非有效的 XML,因此您會收到以下錯誤訊息:
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unexpected char while looking for open tag ('<') character\""
解析度
確認傳遞至 XSLTransform 政策的輸入內容是有效的 XML 酬載,且不為空白。
如要修正範例 XSLTransform 政策的問題,請傳遞有效的 XML 酬載。 例如:
修改
city.xml檔案,使其包含下列 XML 內容:<?xml version="1.0" encoding="UTF-8"?> <root> <City>Bengaluru</City> <Name>Apigee</Name> <Pincode>560016</Pincode> </root>使用 curl 指令呼叫 API,如下所示:
curl -v "http://your_host_alias/v1/xsltransform" -H "Content-Type: application/xml" -X POST -d @city.xml
其中 your_host_alias 是用於存取 API 的公開網域,已在覆寫檔案的
virtualhosts.hostAliases屬性中設定。請參閱「指定設定覆寫」。
原因:前置字元無效
傳遞至 XSLTransform 政策的輸入 XML 酬載含有一個元素,但該元素未在政策中指定的 XSL 檔案中定義為前置字元。
錯誤訊息範例
{
"fault": {
"faultstring": "Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unresolved Prefix at line 1(possibly around char 270)\"",
"detail": {
"errorcode": "steps.xsl.XSLEvaluationFailed"
}
}
}
診斷
找出 XML 轉換政策無法評估的 XSL 檔案,以及失敗原因。在本例中,失敗原因會指出輸入 XML 酬載中特定行號有未解決的前置字元。您可以在錯誤回應的
faultstring元素中找到所有這類資訊。舉例來說,在下列faultstring中,XSL 檔案為XSL-Transform.xsl,失敗原因是Unresolved Prefix,行號為1。"faultstring":"Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unresolved Prefix at line 1(possibly around char 270)\""檢查 XSL 檔案 (如上述步驟 1 所述) 和輸入 XML 酬載的內容。如果輸入 XML 酬載的行號 (如上述步驟 1 所述) 中使用的前置字元不存在於 XSL 檔案中,就會導致錯誤。
以下是導致錯誤的 XSL 範例和對應的 XML 酬載:
XSL-Transform.xsl <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><Life></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></Life></xsl:text> </xsl:template> </xsl:stylesheet>輸入 XML 酬載
<?xml version="1.0"?> <Life:Books> <title>A few of my favorite albums</title> <listitem>Beat Crazy</listitem> <listitem>Here Come the Warm Jets</listitem> <listitem>Kind of Blue</listitem> <listitem>London Calling</listitem> </Life:Books>上述 XML 酬載範例包含
<Life:Books>元素。請注意,XSL 沒有這個前置字串。而是以<xsl:text><Life></xsl:text>為前置字串。因此您會收到下列錯誤訊息:"faultstring":"Evaluation of XSL XSL-Transform.xsl failed with reason: \"Unresolved Prefix at line 1(possibly around char 270)\""
解析度
請確認傳遞至 XSLTransform 政策的輸入 XML 酬載,具有在政策所用 XSL 檔案中定義為前置字元的所有元素格式。
如要修正上述範例 XML 檔案,可以按照下列方式修改檔案:
更新後的輸入 XML 酬載
<?xml version="1.0"?>
<Life>
<title>A few of my favorite albums</title>
<listitem>Beat Crazy</listitem>
<listitem>Here Come the Warm Jets</listitem>
<listitem>Kind of Blue</listitem>
<listitem>London Calling</listitem>
</Life>