Highlighted
Knowledge Partner
Knowledge Partner
408 views

Reformat multi valued attribute

Jump to solution

Hi,

 

Trying to reformat a multivalued attribute in an eDir driver.

I want this:

BA19A/MAT01NPG

BA19B/MAT01NPG

To become this:

BA19A%2FMAT01NP

BA19B%2FMAT01NP

 

And so on.

If we had xpath replace it would be easy but xpath translate can only translate one to one.

Is there any way to do this? Or do I need to create a messy for-each nodeset thing?

 

Labels (1)
0 Likes
1 Solution

Accepted Solutions
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Hi Joakim.

I belive you want to URL encode the values?

If so, add the following namespace to the policy:

Prefix: urlencoder

URI: java.net.URLEncoder

Java extension: Checked

 

Then try:

<do-reformat-op-attr name="yourAttributeName">
	<arg-value type="string">
		<token-xpath expression="urlencoder:encode($current-value, 'UTF-8')"/>
	</arg-value>
</do-reformat-op-attr>

 

Best regards

Marcus

View solution in original post

6 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Hi Joakim.

I belive you want to URL encode the values?

If so, add the following namespace to the policy:

Prefix: urlencoder

URI: java.net.URLEncoder

Java extension: Checked

 

Then try:

<do-reformat-op-attr name="yourAttributeName">
	<arg-value type="string">
		<token-xpath expression="urlencoder:encode($current-value, 'UTF-8')"/>
	</arg-value>
</do-reformat-op-attr>

 

Best regards

Marcus

View solution in original post

Highlighted
Knowledge Partner
Knowledge Partner

That was a nice one!

 

Just found concat as well:

concat(substring-before($current-value,"/"),"%2F",(substring-after($current-value,"/")))

 

But will try your one.

 

Thanks

Highlighted
Knowledge Partner
Knowledge Partner

The key point f the answer is that there is a magical built in local variable called current-value that is only used (As far as I know) in reformat-op-attr. 

 

It implies a loop, and that the logic you define (ECMA call, or concat XPATH) will be applied to each value of Operational attribute  Super powerful. No need to loop or worry about 0, 1, or 2 cases. It is nice and easy and it handles <instance>,<add>, and <modify> events very nicely.

 

Reformat Op Attr is possibly one of the most clever tokens in all of DirXML Script.

 

Side note: Most people ignore it, but the attribute type selector in the GUI is actually quite powerful as well.  Say it is a DN but comes in as a string?  Reformat Op Attr, type DN, and then value is Local Variable current-value and done.

 

 

Highlighted
Knowledge Partner
Knowledge Partner

I have just one a little warning about the use of <do-reformat-op-attr> token in modify operation document.

Reformat-op-attr update not only <add-value> portion, but also <remove-value> part of the document and if this "updated" value doesn't equal current value - it will "break" modify operation.

 

<?xml version="1.0" encoding="UTF-8"?><nds dtdversion="4.0" ndsversion="8.x">
<source>
<product version="4.7.1.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<input>
<modify class-name="User" qualified-src-dn="o=dirXML Test\ou=Users\cn=User1">
<association>o=dirXML Test\ou=Users\cn=User1</association>
<modify-attr attr-name="yourAttributeName">
<remove-value>
<value type="string">old valueBA19A</value>
</remove-value>
<add-value>
<value type="string">BA19A/MAT01NPG</value>
</add-value>
<remove-value>
<value type="string">old valueBA19B</value>
</remove-value>
<add-value>
<value type="string">BA19B/MAT01NPG</value>
</add-value>
</modify-attr>
</modify>
</input>
</nds>

GinoNull :Applying policy: %+C%14CReformat multi valued attribute (modify)%-C.
GinoNull : Applying to modify #1.
GinoNull : Evaluating selection criteria for rule 'Reformat'.
GinoNull : Rule selected.
GinoNull : Applying rule 'Reformat'.
GinoNull : Action: do-reformat-op-attr("yourAttributeName",token-xpath("urlencoder:encode($current-value, 'UTF-8')")).
GinoNull : arg-string(token-xpath("urlencoder:encode($current-value, 'UTF-8')"))
GinoNull : token-xpath("urlencoder:encode($current-value, 'UTF-8')")
GinoNull : Token Value: "old+valueBA19A".
GinoNull : Arg Value: "old+valueBA19A".
GinoNull : arg-string(token-xpath("urlencoder:encode($current-value, 'UTF-8')"))
GinoNull : token-xpath("urlencoder:encode($current-value, 'UTF-8')")
GinoNull : Token Value: "BA19A%2FMAT01NPG".
GinoNull : Arg Value: "BA19A%2FMAT01NPG".
GinoNull : arg-string(token-xpath("urlencoder:encode($current-value, 'UTF-8')"))
GinoNull : token-xpath("urlencoder:encode($current-value, 'UTF-8')")
GinoNull : Token Value: "old+valueBA19B".
GinoNull : Arg Value: "old+valueBA19B".
GinoNull : arg-string(token-xpath("urlencoder:encode($current-value, 'UTF-8')"))
GinoNull : token-xpath("urlencoder:encode($current-value, 'UTF-8')")
GinoNull : Token Value: "BA19B%2FMAT01NPG".
GinoNull : Arg Value: "BA19B%2FMAT01NPG".
GinoNull :Policy returned:
GinoNull :
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product version="4.7.1.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<input>
<modify class-name="User" qualified-src-dn="o=dirXML Test\ou=Users\cn=User1">
<association>o=dirXML Test\ou=Users\cn=User1</association>
<modify-attr attr-name="yourAttributeName">
<remove-value>
<value type="string">old+valueBA19A</value>
</remove-value>
<add-value>
<value type="string">BA19A%2FMAT01NPG</value>
</add-value>
<remove-value>
<value type="string">old+valueBA19B</value>
</remove-value>
<add-value>
<value type="string">BA19B%2FMAT01NPG</value>
</add-value>
</modify-attr>
</modify>
</input>
</nds>

Highlighted
Knowledge Partner
Knowledge Partner
Good,
And thanks. I will test this today.
0 Likes
Highlighted
Knowledge Partner
Knowledge Partner

Yes this works just fine.

Removal of values and changes confirm to the same rule as expected.

 

Only thing that is left is maybe "reset" that will demand some thought since I not only do a convert but also a rename of the attribute depending on a secondary attribute ( not as usual in schema mapping).

 

But that might not be nessicary in this case. The reset that is.

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.