Edit online

AI XPath Extension Functions in Oxygen XML Editor

30 Jun 2025
Read time: 10 minute(s)

Introduction

The integration of AI-driven XPath extension functions in Oxygen XML Editor represents a major step forward in the XML content lifecycle by introducing intelligent automation. These features improve Schematron, XSLT, and XQuery workflows by enabling natural language-driven rephrasing, validation, and custom AI-powered actions directly within your schemas and stylesheets. This post provides an overview of the key functions, practical examples, and configuration options to help you use these AI capabilities effectively, safely, and at scale.

Meet the AI XPath Extension Functions

The Oxygen AI Positron add-on introduces three primary functions (namespace http://www.oxygenxml.com/ai/function) that can be directly used in Schematron, XSLT, XQuery, XProc, and XPath expressions:

ai:transform-content(system, (user, assistant,)* user)

  • Purpose: Transforms or rephrases content using AI, guided by a system prompt and user-provided input.
  • Parameters:
    • system: Context or rule (e.g., “Follow company style guidelines”).
    • user: The input text to be transformed.
    • assistant: (Optional, repeatable) Previous AI responses for context in multi-stage operations.
  • Returns: AI-generated, transformed string.

Sample Use in Schematron:

<sqf:replace match="text()" select="ai:transform-content('Reformulate phrase to be less than 50 words', .)"/>
                

ai:verify-content(system, (user, assistant,)* user)

  • Purpose: Validates content using natural language prompts, returning a Boolean result.
  • Parameters: Same as above.
  • Returns: Boolean (true/false), ideal for driving Schematron assertions.

Sample Use in Schematron:

<sch:report test="ai:verify-content('Does the following content have passive voice?', .)" sqf:fix="rephrase">
    The phrase uses passive voice.
</sch:report>

ai:invoke-action(actionId, extraPrompt, content)

  • Purpose: Executes a pre-configured AI action with additional context or prompts on a given content block.
  • Parameters:
    • actionId: ID of the registered AI action.
    • extraPrompt: Additional context for the action.
    • content: XML node or string to process.
  • Returns: The transformed (or analyzed) string.

Sample Use in Schematron:

<sqf:replace match="text()" select="ai:invoke-action('Reformulate phrase to be less than 50 words', .)"/>

Real-World Example: Optimizing Short Descriptions

Validation & Refactoring in One Step:

This example demonstrates a rule that validates whether a short description exceeds 50 words and provides an automated fix to rephrase it to meet the word limit. The rule uses Schematron and Smart Fix (SQF) to ensure concise and effective short descriptions.

<sch:rule context="shortdesc">
    <sch:report test="count(tokenize(.,'\s+')) > 50" sqf:fix="rephrase">
        The phrase must contain less than 50 words.
    </sch:report>
    <sqf:fix id="rephrase">
        <sqf:description>
            <sqf:title>Rephrase phrase to be less than 50 words</sqf:title>
        </sqf:description>
        <sqf:replace match="text()" select="ai:transform-content('Reformulate phrase to be less than 50 words', .)"/>
    </sqf:fix>
</sch:rule>

Active Voice Checker:

This example illustrates a rule that checks if a short description contains passive voice and provides an automated fix to rephrase it into active voice. The rule leverages AI-based content verification and transformation to enhance the clarity and impact of the text.

<sch:rule context="shortdesc">
    <sch:report test="ai:verify-content('Does the following content have passive voice?', .)"
                sqf:fix="rephrase">The phrase uses passive voice.</sch:report>
    <sqf:fix id="rephrase">
        <sqf:description>
            <sqf:title>Rephrase text to be active voice</sqf:title>
        </sqf:description>
        <sqf:replace match="text()" select="ai:transform-content('Rephrase text to be active voice', .)"/>
    </sqf:fix>
</sch:rule>

Refactor Content Using XSL and AI

The combination of AI and XSLT allows for dynamic and intelligent content transformation. By utilizing AI-driven XPath extension functions, you can automate tasks such as generating alternate text for images, ensuring accessibility and compliance with minimal manual intervention.

Example: Generate Alternate Text for Images

The following XSLT template generates alternate text for images with a `keyref` attribute but without an `alt` attribute. The template employs the `ai:transform-content` function to create a concise alternate text description for the image. The generated alternate text is then added to the `alt` element within the copied image node. This method ensures that all images lacking alternate text are enhanced with meaningful descriptions, improving both accessibility and usability.


<xsl:template match="image[@keyref][not(alt)]">
    <xsl:copy>
        <xsl:apply-templates select="@*"/>
        <alt>
            <xsl:value-of select="
                 ai:transform-content(
                 'Create a short alternate text description for this image:',
                 concat('{attach(', resolve-uri(@href, base-uri()), ')}'))"/>
        </alt>
        <xsl:apply-templates select="node()"/>
    </xsl:copy>
</xsl:template>

This example demonstrates how AI can dynamically generate meaningful alternate text for images, ensuring your content is accessible and enriched with metadata.

Example: Language Translation and Validation

The following XSLT template showcases how AI-driven XPath functions can be used for multi-language translation and validation. In this example, content is translated into French in three variants, then translated back into English. The English translations are compared with the original content to determine the most accurate French translation:


    <xsl:template match="text()">
        <xsl:variable name="agentFrench" select="ai:transform-content('Translate to French in 3 variants ', .)"/>
        <xsl:variable name="agentEnglish" select="ai:transform-content('Translate content from French to English ', $agentFrench)"/>
        <xsl:value-of select="ai:transform-content(
            'Compare the English translation with original content and use the correct French translation. ',
            'Translate to french in 3 variants ', 
            $agentFrench, 
            'Translate from french to english ', 
            $agentEnglish,.)"/>
    </xsl:template>

This method ensures that the final French translation is both accurate and contextually appropriate, leveraging AI's capabilities to process and validate multilingual content effectively.

Configuration Options: Balancing Power and Performance

Oxygen provides several options to customize AI function behavior according to your project’s requirements:

Enable XPath Functions
  • Purpose: Activates AI-driven XPath functions for Schematron/XSLT validation and transformation.
  • Default: Enabled.
Cache Responses and Reuse Them for Identical Prompts
  • Purpose: Minimizes redundant API calls and accelerates validation/transformation by caching AI responses for identical inputs.
  • Default: Enabled.
  • Management: A "Clear cache" button allows you to instantly delete all stored responses.
Cache Size
  • Purpose: Sets an upper limit on the number of responses that can be cached, preventing excessive memory/resource usage.
Notify Me When the Number of Requests Exceeds…
  • Purpose: Provides a safeguard for large-scale operations.
  • Behavior: If the specified threshold of AI requests is exceeded, Oxygen displays a confirmation dialog. You can choose to stop using the XPath AI functions if the volume seems excessive.

Summary: Why Use AI XPath Functions in Oxygen?

  • Express style, validation, and transformation in natural language—eliminating the need for numerous rigid rules.
  • Automate repetitive editorial tasks (e.g., word count, voice, grammar) and provide AI-powered fixes directly in authoring tools.
  • Control resource usage, compliance, and performance through detailed configuration options.

These features are revolutionizing the XML content pipeline, enabling smart, standards-compliant authoring and validation to be effortless and secure.

Ready to integrate AI into your XML workflow? Activate these options in Oxygen XML Editor and start making your content more consistent, compliant, and future-ready today.