0

I am working on a BPMN transform and pull a DMN (decision table) in from an external file. But the namespace declaration in the root element looks a little strange to me, and I cannot figure out how to make my XSL match the required elements in my DMN file.

Here is the file I am referencing:

<definitions xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd" id="definitions_0fyde0d"
    name="definitions" namespace="http://camunda.org/schema/1.0/dmn">
    <decision id="decision" name="DRM01">
        <decisionTable id="decisionTable">
            <input id="input1" label="UserText">
                <inputExpression id="inputExpression1" typeRef="string">
                    <text/>
                </inputExpression>
            </input>
            <output id="output1" label="Subsystem" name="" typeRef="string"/>
            <rule id="row-22012340-2">
                <inputEntry id="UnaryTests_1hacpom">
                    <text>
                        <![CDATA["signal"]]>
                    </text>
                </inputEntry>
                <outputEntry id="LiteralExpression_0wvuvyc">
                    <text>
                        <![CDATA["input"]]>
                    </text>
                </outputEntry>
            </rule>
            <rule id="row-22012340-3">
                <inputEntry id="UnaryTests_0cmpu76">
                    <text>
                        <![CDATA["screen"]]>
                    </text>
                </inputEntry>
                <outputEntry id="LiteralExpression_0hkc81e">
                    <text>
                        <![CDATA["output"]]>
                    </text>
                </outputEntry>
            </rule>
            <rule id="row-22012340-4">
                <inputEntry id="UnaryTests_02k6et6">
                    <text/>
                </inputEntry>
                <outputEntry id="LiteralExpression_1wwd9ka">
                    <text>
                        <![CDATA["not sure"]]>
                    </text>
                </outputEntry>
            </rule>
        </decisionTable>
    </decision>
</definitions>

I added the namespace declaration for dmn into my XSL:

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:bpmn="http://www.omg.org/spec/BPMN/20100524/MODEL" 
    xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" 
    xmlns:di="http://www.omg.org/spec/DD/20100524/DI" 
    xmlns:dc="http://www.omg.org/spec/DD/20100524/DC" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:dmn="http://camunda.org/schema/1.0/dmn"
    exclude-result-prefixes="xs bpmn bpmndi di dc xsi dmn"
    version="2.0">

I have tried all kinds of options to match specific elements in the DMN file, but I am either getting all the CDATA or nothing at all.

Here is the line that calls the template for DMN contents:

<xsl:apply-templates select="$docfile/*" mode="dmn"/>

I can see that the element is matched when I create a template that pushes out the local-name() of the matched element. That would mean the element does not have a namespace. I use this template to process only the elements in my DMN file:

<xsl:template match="*" mode="dmn">
    <xsl:apply-templates select="descendant::dmn:rule"/>
</xsl:template>

This gives no matches at all, even though I do have a template for dmn:rule. When I remove the namespace in both the apply call and the template match clause, I get the same result.

I am suspecting something about the namespace is not correct, but I cannot figure it out.

Ed Bangga
  • 11,622
  • 4
  • 10
  • 29
4everJang
  • 147
  • 1
  • 8
  • 2
    You only need to declare `xmlns:ns0="http://www.omg.org/spec/DMN/20151101/dmn.xsd"` then use the `ns0` prefix when addressing elements in your XML source - see: https://stackoverflow.com/questions/34758492/xslt-transform-doesnt-work-until-i-remove-root-node/34762628#34762628 – michael.hor257k Sep 30 '17 at 10:35
  • Found the solution: I was using the namespace definition that is in the DMN file header and I should use the xmlns attribute instead. Still I do not understand why there would be two different references to namespaces. Can somebody explain what these mean (or tell me that the two attributes are not good practice) ? Thanks. – 4everJang Sep 30 '17 at 10:37
  • 2
    The `xmlns="http://www.omg.org/spec/DMN/20151101/dmn.xsd"` part is a *declaration* (not an *attribute*) that puts the root element (and by inheritance, its descendants) in a namespace. The `namespace="http://camunda.org/schema/1.0/dmn"` part is just an attribute carrying some information which may be useful for some other purpose, or not at all. – michael.hor257k Sep 30 '17 at 10:46
  • OK. Thanks for that. The namespace attribute was getting me confused, obviously. I have the script working now. Was trying that switch at the same moment you wrote your first comment, it seems. – 4everJang Sep 30 '17 at 11:08

0 Answers0