Novell is now a part of Micro Focus

Using Recursion to Capture the User Info From the Event Tag

Novell Cool Solutions: Feature
By Simon Lau

Digg This - Slashdot This

Posted: 13 Mar 2003


In most implementations of DirXML technology, multiple eDirectory trees are involved, and most often you need a User ID to perform some operations or to complete some part of your style sheet when constructing the programming logic. To do this, normally you would rely on capturing the value of attribute "CN" in the incoming XML document. In some cases, however, the attribute "CN" does not exist in the incoming XML document, and there are no other attributes that can give you the User ID.

There is one easy way to find the User ID, and that is by looking at the source dn attribute of the event tag. For example, a modify event from eDirectory driver:

<modify class-name="User"  src-dn="\TREE\O\ou1\ou2\JohnD">

Now, you are wondering --- how do I extract "JohnD" from the src-dn? There is an easy way to do it by using a small recursive template. I named this template "get-name". First you need to add a couple of lines in your style sheet to call this template and store the result in a variable. Also, you need to pass the original src-dn as a parameter when calling the "get-name" template. For example:

<xsl:template match="modify">
<xsl:variable name="username">
  <xsl:call-template name="get-name">
    <xsl:with-param name="old-dn" select="@src-dn"/>

The src-dn is passed to the template as variable "old-dn". The "get-name" template uses the simple "substring-after" function to parse the incoming src-dn string. The "substring-after" finds the string behind the first slash "\", and the result is stored in a temporary variable named "remaining", which is used later as the input parameter for the recursion.

A simple choose/when/otherwise logic is used to check and see if there are any more slashes in the remaining string using the "contains" function. If no more slashes exist in the string, the last instance of "remaining" will be returned as a result.

The complete "get-name" template is as follows:

<xsl:template name="get-name">
<xsl:param name="old-dn"/>
    <xsl:variable name="remaining">
      <xsl:value-of select="substring-after($old-dn,'\')"/>
    <xsl:when test="contains($remaining,'\')">		
      <xsl:call-template name="get-name">
        <xsl:with-param name="old-dn" select="$remaining"/>
      <xsl:value-of select="$remaining"/>

The above method can be used either in the Event Transform or Placement style sheet in the publisher channel. It will work in any style sheet as long as the incoming XML document contains the src-dn (source dn) in the event tag.

Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions.

© Copyright Micro Focus or one of its affiliates