Skip to main content
Skip table of contents

checkXML

Learn how the XML checking function checkXML of the Java class de.softproject.xsl.XSLHelper is used within XSL mappings.


The Java class de.softproject.xsl.XSLHelper is located within the X4 Server library x4-client.jar (under <X4>\Server\<wildfly>\modules\de\softproject\x4\client\main).

An XSL mapping using this help class, can't be executed in the transformation preview of the Mapping Editor.

Method Description

checkXML(
java.lang.String URL)

Checks if a document, which is referenced by any valid URL as string according to java.lang.String, is a well-formed XML and returns a value of the type boolean.

Valid URL protocols are:

  • file:/// for local files
  • xstore:// for repository documents
  • context: for variables within the context of the current X4 process instance

Example

The following XSL mapping accesses an XML document, which is stored in a process variable Var1 at runtime of an associated X4 process, via the context: URL Protocol. Thereby, the included Java method checkXML first checks, if the document is well-formed. In the following steps the document is processed and an error handling occurs.

HTML/XML
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet exclude-result-prefixes="xslhelper" version="1.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xslhelper="de.softproject.xsl.XSLHelper">
  <xsl:output indent="yes" media-type="text/xml" method="xml"/>
  <xsl:template match="/">
    <Output>
      <!-- Checking if Var1 is XML or not  -->
      <!-- If true, output it -->
      <xsl:choose>
        <xsl:when test="xslhelper:checkXML('context:Var1')">
          <!-- Define an XSL variable and assign a process variable "Var1",
	            that is accessible as an external document via context: protocol -->
          <xsl:variable name="Var1Content" select="document('context:Var1')"/>
          <xsl:attribute name="isXML">
            <xsl:text>Yes</xsl:text>
          </xsl:attribute>
          <!-- Output XML content of Var1 -->
          <Data>
            <xsl:copy-of select="$Var1Content"/>
          </Data>
        </xsl:when>
        <xsl:otherwise>
          <xsl:attribute name="isXML">
            <xsl:text>No</xsl:text>
          </xsl:attribute>
        </xsl:otherwise>
      </xsl:choose>
    </Output>
  </xsl:template>
</xsl:stylesheet>
JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.