sma2006 Outstanding Contributor.
Outstanding Contributor.
158 views

xpath expression help to add element to ouptut

Jump to solution

Hello,

I'm trying to add an empty element to an output after a query.

The output is :

<nds dtdversion="4.0" ndsversion="8.x">
  <source>
    <product edition="Advanced" version="4.6.3.0">DirXML</product>
    <contact>NetIQ Corporation</contact>
  </source>
  <output>
    <instance class-name="User" event-id="0" qualified-src-dn="O=data\OU=users\CN=BLA" src-dn="\TESTA\data\users\BLA" src-entry-id="34286">
      <association state="associated">BLA</association>
      <attr attr-name="CN">
        <value naming="true" timestamp="1433156258#28" type="string">BLA</value>
      </attr>
      <attr attr-name="Surname">
        <value timestamp="1433156258#6" type="string">NAME</value>
      </attr>
      <attr attr-name="Given Name">
        <value timestamp="1433156258#5" type="string">Belinda</value>
      </attr>
    </instance>
    <status event-id="0" level="success"></status>
  </output>
</nds>

 

I would like to add an element that is currently an empty attribute, for example email:

<nds dtdversion="4.0" ndsversion="8.x">
  <source>
    <product edition="Advanced" version="4.6.3.0">DirXML</product>
    <contact>NetIQ Corporation</contact>
  </source>
  <output>
    <instance class-name="User" event-id="0" qualified-src-dn="O=data\OU=users\CN=BLA" src-dn="\TESTA\data\users\BLA" src-entry-id="34286">
      <association state="associated">BLA</association>
      <attr attr-name="CN">
        <value naming="true" timestamp="1433156258#28" type="string">BLA</value>
      </attr>
      <attr attr-name="Surname">
        <value timestamp="1433156258#6" type="string">NAME</value>
      </attr>
      <attr attr-name="Given Name">
        <value timestamp="1433156258#5" type="string">Belinda</value>
      </attr>
   <attr attr-name="Internet Email Address">
        <value type="string"></value>
      </attr>
    </instance>
    <status event-id="0" level="success"></status>
  </output>
</nds>

Thanks for the help.

Sylvain

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Knowledge Partner
Knowledge Partner

Re: xpath expression help to add element to ouptut

Jump to solution
The instance and the status are two separate operations and your policies will be applied to both of them separately as well. You'll see something like "Applying policy to instance #1" and "Applying policy to status #2" in a level 3 trace.
Also your policies are limited to access the current operation and operations added by the policy itself. You cannot access the status node from the instance node and vice versa.
Try something like this:

<rule>
<description>Test Add element </description>
<conditions>
<or>
<if-operation mode="nocase" op="equal">instance</if-operation>
</or>
</conditions>
<actions>
<do-append-xml-element expression="." name="attr"/>
<do-set-xml-attr expression="attr[last()]" name="attr-name">
<arg-string>
<token-text xml:space="preserve">Internet Email Address</token-text>
</arg-string>
</do-set-xml-attr>
<do-append-xml-element expression="attr[last()]" name="value"/>
<do-break/>
</actions>
</rule>
______________________________________________
https://www.is4it.de/identity-access-management
5 Replies
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: xpath expression help to add element to ouptut

Jump to solution

I tried that :

 <rule>
  <description>Test Add element </description>
<conditions>
   <and>
    <if-operation mode="regex" op="not-equal">instance</if-operation>
    <if-operation mode="nocase" op="not-equal">driver-operation-data</if-operation>
   </and>
  </conditions>
  <actions>
   <do-if>
    <arg-conditions>
     <and>
      <if-operation mode="regex" op="equal">status</if-operation>
      <if-xpath op="true">count(//nds//instance)>0</if-xpath>
      <if-xpath op="not-true">//instance[@class-name="DirXML-Driver"]</if-xpath>
     </and>
    </arg-conditions>
    <arg-actions>
     <do-append-xml-element expression='../instance/attr[@name="Internet Email Address"]' name="attr"/>
     <do-append-xml-element expression='./instance/attr[@name="Internet Email Address"]/"test"' name="value"/>
    </arg-actions>
    <arg-actions/>
   </do-if>
   <do-break/>
  </actions>
 </rule>

 

After the condition, my context must be <status>, so I try to add my new element in : ./instance

But this does not work at all, as the driver did not start.

Any help ?

 

thx

 

Sylvain

0 Likes
Knowledge Partner
Knowledge Partner

Re: xpath expression help to add element to ouptut

Jump to solution

Quick and dirty solution (example of adding "empty"  Surname2 attribute).

 

<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE policy PUBLIC "policy-builder-dtd" "C:\Novell\Designer\plugins\com.novell.idm.policybuilder_4.0.0.201404231247\DTD\dirxmlscript4.0.2.dtd"><policy>
<rule>
<description>Inject</description>
<conditions>
<and/>
</conditions>
<actions>
<do-clone-op-attr dest-name="Surname2" src-name="Surname"/>
<do-reformat-op-attr name="Surname2">
<arg-value type="string"/>
</do-reformat-op-attr>
</actions>
</rule>
</policy>

 

Result:

<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Advanced" version="4.6.3.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<output>
<instance class-name="User" event-id="0" qualified-src-dn="O=data\OU=users\CN=BLA" src-dn="\TESTA\data\users\BLA" src-entry-id="34286">
<association state="associated">BLA</association>
<attr attr-name="CN">
<value naming="true" timestamp="1433156258#28" type="string">BLA</value>
</attr>
<attr attr-name="Surname">
<value timestamp="1433156258#6" type="string">NAME</value>
</attr>
<attr attr-name="Given Name">
<value timestamp="1433156258#5" type="string">Belinda</value>
</attr>
<attr attr-name="Surname2">
<value type="string"/>
</attr>
</instance>
<status event-id="0" level="success"/>
</output>
</nds>

0 Likes
Knowledge Partner
Knowledge Partner

Re: xpath expression help to add element to ouptut

Jump to solution
The instance and the status are two separate operations and your policies will be applied to both of them separately as well. You'll see something like "Applying policy to instance #1" and "Applying policy to status #2" in a level 3 trace.
Also your policies are limited to access the current operation and operations added by the policy itself. You cannot access the status node from the instance node and vice versa.
Try something like this:

<rule>
<description>Test Add element </description>
<conditions>
<or>
<if-operation mode="nocase" op="equal">instance</if-operation>
</or>
</conditions>
<actions>
<do-append-xml-element expression="." name="attr"/>
<do-set-xml-attr expression="attr[last()]" name="attr-name">
<arg-string>
<token-text xml:space="preserve">Internet Email Address</token-text>
</arg-string>
</do-set-xml-attr>
<do-append-xml-element expression="attr[last()]" name="value"/>
<do-break/>
</actions>
</rule>
______________________________________________
https://www.is4it.de/identity-access-management
Knowledge Partner
Knowledge Partner

Re: xpath expression help to add element to ouptut

Jump to solution

Good work, Lothar!

The perfect example of using "low level" commands for adding new attributes to the doc!

0 Likes
sma2006 Outstanding Contributor.
Outstanding Contributor.

Re: xpath expression help to add element to ouptut

Jump to solution
Thanks a lot it work fine.
0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.