> ## Documentation Index
> Fetch the complete documentation index at: https://docs.iyzpdf.com/llms.txt
> Use this file to discover all available pages before exploring further.

# XML To HTML

> Transform XML and XSLT into HTML.

## Notes

* Credits: `1`
* XML is limited to `5 MB`
* XSLT is limited to `1 MB`
* Invalid XML or XSLT returns a validation error
* The default attachment name is `output.html`


## OpenAPI

````yaml /openapi.json post /convert/xml-to-html
openapi: 3.0.3
info:
  title: IyzPdf Client API
  version: 1.0.0
  description: Client-facing document conversion and PDF editing endpoints for IyzPdf.
servers:
  - url: https://api.iyzpdf.com/v1
security:
  - ApiKeyAuth: []
tags:
  - name: Conversion
  - name: PDF Editing
paths:
  /convert/xml-to-html:
    post:
      tags:
        - Conversion
      summary: Transform XML with XSLT into HTML
      operationId: xmlToHtml
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/XmlToHtmlRequest'
            examples:
              invoiceTransform:
                summary: Inline XML and XSLT
                value:
                  xml: >-
                    <?xml version="1.0"
                    encoding="UTF-8"?><invoice><number>INV-1001</number></invoice>
                  xslt: >-
                    <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet
                    version="1.0"
                    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
                    match="/"><html><body><h1><xsl:value-of
                    select="invoice/number"
                    /></h1></body></html></xsl:template></xsl:stylesheet>
          multipart/form-data:
            schema:
              type: object
              properties:
                xmlFile:
                  type: string
                  format: binary
                xsltFile:
                  type: string
                  format: binary
              required:
                - xmlFile
                - xsltFile
            examples:
              xmlAndXsltFiles:
                summary: XML and XSLT uploads
                value:
                  xmlFile: (binary)
                  xsltFile: (binary)
      responses:
        '200':
          description: Successful response.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/BinaryFileMetadataResponse'
              example:
                fileName: output.html
                size: 4281
                creditsUsed: 1
                creditsRemaining: 49
                contentType: text/html; charset=utf-8
            text/html:
              schema:
                type: string
              example: <html><body><h1>INV-1001</h1></body></html>
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '402':
          $ref: '#/components/responses/PaymentRequired'
        '413':
          $ref: '#/components/responses/PayloadTooLarge'
        '415':
          $ref: '#/components/responses/UnsupportedMediaType'
        '429':
          $ref: '#/components/responses/RateLimited'
        '500':
          $ref: '#/components/responses/InternalError'
      x-codeSamples:
        - label: curl
          lang: bash
          source: |-
            curl --request POST \
              --url https://api.iyzpdf.com/v1/convert/xml-to-html \
              --header "X-API-Key: $IYZPDF_API_KEY" \
              --header "Content-Type: application/json" \
              --data '{
                "xml": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><invoice><number>INV-1001</number></invoice>",
                "xslt": "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><html><body><h1><xsl:value-of select=\"invoice/number\" /></h1></body></html></xsl:template></xsl:stylesheet>"
              }' \
              --output invoice.html
        - label: python
          lang: python
          source: |-
            import os
            import requests

            api_key = os.environ["IYZPDF_API_KEY"]
            payload = {
                "xml": "<?xml version="1.0" encoding="UTF-8"?><invoice><number>INV-1001</number></invoice>",
                "xslt": "<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><h1><xsl:value-of select="invoice/number" /></h1></body></html></xsl:template></xsl:stylesheet>",
            }

            response = requests.post(
                "https://api.iyzpdf.com/v1/convert/xml-to-html",
                headers={"X-API-Key": api_key},
                json=payload,
                timeout=60,
            )

            if not response.ok:
                raise Exception(response.text)

            with open("invoice.html", "w", encoding="utf-8") as output_file:
                output_file.write(response.text)
        - label: javascript
          lang: javascript
          source: >-
            import { writeFile } from "node:fs/promises";


            const apiKey = process.env.IYZPDF_API_KEY;


            const response = await
            fetch("https://api.iyzpdf.com/v1/convert/xml-to-html", {
              method: "POST",
              headers: {
                "X-API-Key": apiKey,
                "Content-Type": "application/json"
              },
              body: JSON.stringify({
                xml: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><invoice><number>INV-1001</number></invoice>",
                xslt: "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><html><body><h1><xsl:value-of select=\"invoice/number\" /></h1></body></html></xsl:template></xsl:stylesheet>"
              })
            });


            if (!response.ok) {
              throw new Error(await response.text());
            }


            await writeFile("invoice.html", await response.text());
        - label: php
          lang: php
          source: |-
            <?php

            $apiKey = getenv('IYZPDF_API_KEY');

            $payload = [
                'xml' => '<?xml version="1.0" encoding="UTF-8"?><invoice><number>INV-1001</number></invoice>',
                'xslt' => '<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/"><html><body><h1><xsl:value-of select="invoice/number" /></h1></body></html></xsl:template></xsl:stylesheet>',
            ];

            $ch = curl_init('https://api.iyzpdf.com/v1/convert/xml-to-html');

            curl_setopt_array($ch, [
                CURLOPT_POST => true,
                CURLOPT_RETURNTRANSFER => true,
                CURLOPT_HTTPHEADER => [
                    'X-API-Key: ' . $apiKey,
                    'Content-Type: application/json',
                ],
                CURLOPT_POSTFIELDS => json_encode($payload),
            ]);

            $html = curl_exec($ch);
            $status = curl_getinfo($ch, CURLINFO_HTTP_CODE);

            if ($html === false || $status !== 200) {
                throw new RuntimeException('Request failed: ' . curl_error($ch) . PHP_EOL . $html);
            }

            file_put_contents('invoice.html', $html);
            curl_close($ch);
        - label: java
          lang: java
          source: |-
            import java.net.URI;
            import java.net.http.HttpClient;
            import java.net.http.HttpRequest;
            import java.net.http.HttpResponse;
            import java.nio.file.Files;
            import java.nio.file.Path;

            public class XmlToHtmlExample {
                public static void main(String[] args) throws Exception {
                    String apiKey = System.getenv("IYZPDF_API_KEY");
                    HttpClient client = HttpClient.newHttpClient();

                    String json = """
                        {
                          "xml": "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><invoice><number>INV-1001</number></invoice>",
                          "xslt": "<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?><xsl:stylesheet version=\\"1.0\\" xmlns:xsl=\\"http://www.w3.org/1999/XSL/Transform\\"><xsl:template match=\\"/\\"><html><body><h1><xsl:value-of select=\\"invoice/number\\" /></h1></body></html></xsl:template></xsl:stylesheet>"
                        }
                        """;

                    HttpRequest request = HttpRequest.newBuilder()
                        .uri(URI.create("https://api.iyzpdf.com/v1/convert/xml-to-html"))
                        .header("X-API-Key", apiKey)
                        .header("Content-Type", "application/json")
                        .POST(HttpRequest.BodyPublishers.ofString(json))
                        .build();

                    HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());

                    if (response.statusCode() != 200) {
                        throw new RuntimeException("Request failed with status " + response.statusCode());
                    }

                    Files.writeString(Path.of("invoice.html"), response.body());
                }
            }
        - label: c#
          lang: csharp
          source: |-
            using System.Net.Http.Json;

            var apiKey = Environment.GetEnvironmentVariable("IYZPDF_API_KEY");
            using var client = new HttpClient();

            client.DefaultRequestHeaders.Add("X-API-Key", apiKey);

            var payload = new
            {
                xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><invoice><number>INV-1001</number></invoice>",
                xslt = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><xsl:stylesheet version=\"1.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\"><xsl:template match=\"/\"><html><body><h1><xsl:value-of select=\"invoice/number\" /></h1></body></html></xsl:template></xsl:stylesheet>"
            };

            using var response = await client.PostAsJsonAsync(
                "https://api.iyzpdf.com/v1/convert/xml-to-html",
                payload);

            response.EnsureSuccessStatusCode();

            var html = await response.Content.ReadAsStringAsync();
            await File.WriteAllTextAsync("invoice.html", html);
components:
  schemas:
    XmlToHtmlRequest:
      type: object
      properties:
        xml:
          type: string
        xslt:
          type: string
      required:
        - xml
        - xslt
      example:
        xml: >-
          <?xml version="1.0"
          encoding="UTF-8"?><invoice><number>INV-1001</number></invoice>
        xslt: >-
          <?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template
          match="/"><html><body><h1><xsl:value-of select="invoice/number"
          /></h1></body></html></xsl:template></xsl:stylesheet>
    BinaryFileMetadataResponse:
      type: object
      properties:
        fileName:
          type: string
        size:
          type: integer
          format: int32
        creditsUsed:
          type: integer
          format: int32
        creditsRemaining:
          type: integer
          format: int32
          nullable: true
        contentType:
          type: string
      required:
        - fileName
        - size
        - creditsUsed
        - contentType
      example:
        fileName: output.pdf
        size: 183240
        creditsUsed: 1
        creditsRemaining: 49
        contentType: application/pdf
    ErrorResponse:
      type: object
      properties:
        error:
          type: object
          properties:
            code:
              type: string
            message:
              type: string
            creditsRequired:
              type: integer
              format: int32
              nullable: true
            creditsBalance:
              type: integer
              format: int32
              nullable: true
            purchaseUrl:
              type: string
              nullable: true
          required:
            - code
            - message
      required:
        - error
      example:
        error:
          code: INVALID_REQUEST
          message: The request payload is invalid or incomplete.
  responses:
    BadRequest:
      description: Validation error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INVALID_REQUEST
              message: The request payload is invalid or incomplete.
    Unauthorized:
      description: Missing or invalid API key
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNAUTHORIZED
              message: Missing or invalid API key.
    PaymentRequired:
      description: Insufficient credits
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: INSUFFICIENT_CREDITS
              message: You need more credits to complete this request.
              creditsRequired: 2
              creditsBalance: 0
              purchaseUrl: https://iyzpdf.com/portal/credits
    PayloadTooLarge:
      description: Payload too large
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: FILE_TOO_LARGE
              message: >-
                The uploaded file or request body exceeds the allowed size
                limit.
    UnsupportedMediaType:
      description: Unsupported media type
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: UNSUPPORTED_MEDIA_TYPE
              message: The uploaded file type or content type is not supported.
    RateLimited:
      description: Rate limit exceeded
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: RATE_LIMIT_EXCEEDED
              message: Too many requests. Please retry after the rate limit resets.
    InternalError:
      description: Processing failed
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
          example:
            error:
              code: PROCESSING_FAILED
              message: The document could not be processed.
  securitySchemes:
    ApiKeyAuth:
      type: apiKey
      in: header
      name: X-API-Key
      description: Send your server-side API key in the X-API-Key header.

````