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 Valid URL protocols are:
|
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.
<?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>