Boosting XML Development with AI-Driven Code Actions in Oxygen XML Editor
Introduction
Discover how AI-powered actions in Oxygen XML Editor revolutionize XML schema and XSLT stylesheet development. With AI actions to explain, annotate, generate, or document code, chat with the AI about certain code, and to suggest refactoring, these tools help developers work faster and smarter. As XML workflows become more complex, smarter tools are essential for editing, collaboration, and refactoring. The AI Positron Assistant in Oxygen XML Editor empowers users with a suite of intelligent actions designed for modern code development.
In this post, we’ll explore the main AI actions that act on XML-development languages, such as XML Schema, XSLT, and Schematron — Explain Code, Chat About Code, Document Code, Annotate Code, Generate Code, and Suggest Refactoring, and we'll show examples of how they boost productivity when working with XSLT.
Watch the video demonstration: Using AI for XML Development in Oxygen XML Editor
AI-Powered Code Actions Overview
AI Positron integrates smoothly with Oxygen XML Editor/Developer to improve code quality, enhance understanding, and automate repetitive development tasks. Here’s an overview of the main capabilities and their practical benefits for each AI-assisted development action:
- Explain Code
- Select any code fragment or place your cursor inside an element and AI Positron will immediately generate an explanation. This helps you quickly understand legacy XSLT templates, Schematron rules, or complex schema definitions, reducing time spent deciphering unfamiliar code.
- Chat About Code
- Start an interactive chat with the AI about the selected code. Ask questions like "What’s the purpose of this constraint?" or "How can I optimize this template?" to brainstorm improvements, resolve technical issues, and make informed changes faster.
- Document Code
- With a single action, generate clear and concise XML comments for selected XSLT, XML Schema, or Schematron code. These summaries, added before the code block make onboarding, code reviews, and future maintenance easier.
- Annotate Code
- Automatically add comments to entire documents or specific elements. The generated annotations clarify intent, constraints, and relationships, streamlining documentation and sharing knowledgeacross your team.
- Generate Code
- Describe the code or transformation you need and let AI Positron create XSLT templates, Schematron assertions, XSD complex types, or JSON Schema objects. The AI reuses existing components where possible, supporting DRY (don't repeat yourself) principles and speeds up the development process.
- Suggest Refactoring
- Receive suggestions to simplify code and improve modularity.The AI can upgrade the XSLT version, split large templates, extract reusable code, or add clarifying comments. Refactoring helps you modernize and maintain code with less effort.
Practical Example: Accelerate XSLT Development with AI Actions
As an XSLT developer, you can significantly speed up your workflow and improve code quality using the AI Positron add-on in Oxygen XML Editor. Here’s an example showing how to use AI actions with real XSLT code:
-
Understand Existing Templates with Explain Code - Suppose you encounter the following template:
<xsl:template match="section"> <div class="section"> <h2><xsl:value-of select="title"/></h2> <xsl:apply-templates select="para"/> </div> </xsl:template>
Select this code and use the Explain Code action. The AI will output:This template matches
<section>
elements, creates a<div>
with class "section", outputs the section title in an<h2>
, and applies templates to all<para>
children. -
Discuss and Improve Code with Chat About Code - If you want to optimize or extend the previous template, select it and use the Chat About Code action. For example, you might ask:
How can I add a check to display a warning if the section has no title?
The AI suggested:
<xsl:template match="section"> <div class="section"> <xsl:choose> <xsl:when test="title"> <h2><xsl:value-of select="title"/></h2> </xsl:when> <xsl:otherwise> <div class="warning">[WARNING: section has no title]</div> <xsl:message terminate="no"> WARNING: a <section> element has no <title>. </xsl:message> </xsl:otherwise> </xsl:choose> <xsl:apply-templates select="para"/> </div> </xsl:template>
-
Document Templates with Document Code - To help with future maintenance, select the previous updated template and use the Document Code action. The AI will insert a comment before the template:
<!-- Outputs each section as a div with its title in an h2 header. Issues a warning placeholder when the title is missing and continues processing paragraphs. --> <xsl:template match="section"> [...] </xsl:template>
-
Annotate Intricate Logic with Annotate Code - For complex templates, use the Annotate Code action to insert both template documentation and inline comments, all comments in this example were generated by AI:
<!-- Template that matches the "book" element in the input XML and transforms it into HTML. The structure includes a main <div> containing the book's title and all chapters with their sections. --> <xsl:template match="book"> <div> <!-- Output the book's title inside an <h1> tag --> <h1> <xsl:value-of select="title"/> </h1> <!-- Iterate over each "chapter" child element of "book" --> <xsl:for-each select="chapter"> <!-- Output the chapter's title inside an <h2> tag --> <h2> <xsl:value-of select="title"/> </h2> <!-- Apply templates to all "section" elements within the current chapter. This allows further processing of sections by other templates. --> <xsl:apply-templates select="section"/> </xsl:for-each> </div> </xsl:template>
-
Generate New Templates with Generate Code - Place your cursor after a comment that describes the desired functionality and use the Generate Code action:
<!-- Generate a template that outputs all author names in a comma-separated list -->
The AI generates:
<xsl:template match="authors"> <p> <xsl:for-each select="author"> <xsl:value-of select="name"/> <xsl:if test="position() != last()">, </xsl:if> </xsl:for-each> </p> </xsl:template>
-
Refactor Complex Code with Suggest Refactoring - If you have a monolithic template such as:
<xsl:template match="book"> <div> <h1> <xsl:value-of select="title"/> </h1> <xsl:for-each select="chapter"> <h2> <xsl:value-of select="title"/> </h2> <xsl:apply-templates select="section"/> </xsl:for-each> </div> </xsl:template>
This template processes the entire book structure in a single, nested template using <xsl:for-each> for chapters and <xsl:apply-templates> for sections. While this works, it can become difficult to maintain, extend, or debug as the complexity of the XML structure grows.
Use the Suggest Refactoring action and the AI will suggest to break it into smaller templates:
<xsl:template match="book"> <div> <h1> <xsl:value-of select="title"/> </h1> <xsl:apply-templates select="chapter"/> </div> </xsl:template> <xsl:template match="chapter"> <h2> <xsl:value-of select="title"/> </h2> <xsl:apply-templates select="section"/> </xsl:template> <xsl:template match="section"> <h3> <xsl:value-of select="title"/> </h3> <!-- Add more processing for section content here if needed --> </xsl:template>
By breaking the logic into separate templates for <book>, <chapter>, and <section>, each template is focused on a single responsibility. This modular approach makes it easier to understand what each part of the code is doing, and to locate or update specific logic.
Summary: With these AI-powered actions, you can quickly understand, document, generate, refactor, and annotate XSLT code, making your XSLT development process faster and your stylesheets easier to maintain. For more hands-on examples, see the AI Positron Assistant samples on GitHub.
Creating a Custom AI Action
For advanced automation and customized workflows, Oxygen lets you build and integrate custom AI actions directly into your workspace. These actions extend Oxygen’s standard tools and give you greater flexibility and control over AI-driven tasks.
Use the New Document wizard to create an AI Positron Custom Action file. This file contains an action definition in JSON format, where you can specify the action's intent, parameters, and AI logic.
Oxygen offers automatic validation and content completion for these files, so you can edit and maintain them with confidence. Work in text mode for exact control, or switch to the Author visual editing mode for a guided, interactive experience.
For example, you can create an AI action that generates a new XSLT document from specific content with a simple guided workflow. You define the action logic and workflow in JSON, and the integrated AI produces a complete XSLT stylesheet based on your instructions.
The following JSON shows a custom AI action that generates an XSLT 3.0 document based on provided source content:
{
"id": "create.new.xslt",
"title": "Create New XSLT",
"output-action": "create-new-document",
"context": "# CONTEXT #\nYou will act as a senior XSLT developer.\n\n # OBJECTIVE #\nYou are tasked with creating an XSLT starting from the provided text. Create an XSLT with version 3.0 \n\n# RESPONSE #\nRespond with just the XSLT file content, without any other explanations.",
"parameters": {
"function_refs": [
{"ref": "get_content_for_document_url"}
]
}
}
In Author mode, this action appears as a structured form, allowing you to configure and review the action visually:
![[ The Create New XSLT action displayed in Author mode, with editable fields and advanced AI parameters. ]](../images/customAIActionXSL.png)
In this setup, you supply context, objectives, the desired output action, and any helper functions (such as extracting content from a document URL). The AI then generates the XSLT file and returns only the requested code.
For a detailed walkthrough on creating and customizing AI actions in Oxygen, see the official documentation: Creating Custom AI Actions in Oxygen.
Video Tutorial: How to Create Custom AI Actions in Oxygen
Tips and Best Practices
- Focused Selection: Select small code blocks for targeted explanations and documentation.
- Iterative Chat: Use the Chat About Code action for ongoing improvements, to ask questions, make changes, and regenerate code snippets interactively.
- Refactor Files: Run the Suggest Refactoring action on your code to update it to modern standards and to create more readable, reusable modules.
- Comprehensive Comments: Annotate large, multi-template XSLT or XSD files to improve shared understanding and make onboarding easier.
- Explore Samples: Review and adapt provided samples to help your team get started quickly.
Conclusion
AI-driven actions in Oxygen XML Editor are changing how developers approach code understanding, editing, and maintenance. Whether you’re explaining a Schematron rule, documenting a schema, generating new validation logic, or refactoring for the future, AI Positron delivers efficiency at every step. Take advantage of these tools to elevate your XML development workflow.
To experiment and learn more, check out the Code Development subfolder in the AI Positron samples project.