On Tue, 07 Feb 2006 20:12:02 GMT, Daniel.reznick@mssm.edu wrote:

>Thanks a lot for your respond. Could you please point me to the posting
>you mention bellow. I did a search and couldn't locate that XSLT.


Here you go. This stylesheet uses Given Name and Surname to generate a unique CN
based on the first letter of Given Name (G), up to six characters of Surname
(Ssssss). To resolve the unique problem, it lops off a letter of Surname and
replaces it with a number, then two letters, then three letters, etc. until it
runs out of unique names (GSs9999). The CN generated is always exactly 7
characters long, so names are also padded with a counter if Surname is shorter
than 6 characters.

Examples:

Joe Smith ==> JSmith1
John Smith ==> JSmith2
Joe Hacker ==> JHacker
John Hacker ==> JHacke1
Jane Hacker ==> JHacke2

You'll have to hack this a bit to fit your exact requirements, but it shouldn't
be too hard.


<?xml version="1.0" encoding="UTF-8"?><xsl:transform version="1.0"
xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsQueryProcessor"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<!--
################################################## #################
PublisherCreateSS:
This Style Sheet is a template for the DirXML Driver 5.0 for PeopleSoft
################################################## #################
-->
<!--
The following is for testing the stylesheet outside of DirXML so things
are
tabbed correctly an pretty to look at
-->
<xsl:strip-space elements="*"/>
<xslreserve-space elements="value,component"/>
<xslutput indent="yes" method="xml"/>
<!--
dirxml always passes two stylesheet parameters to an XSLT rule: an
inbound
and outbound query processor
-->
<xslaram name="srcQueryProcessor"/>
<xslaram name="destQueryProcessor"/>
<!--
################################################## #################
match <add> elements.
This template will:
- Build a new 'CN' attribute for the User being created.
################################################## #################
-->
<xsl:template match="add">
<!--
copy the add through
-->
<xsl:copy>
<!--
copy any attributes
-->
<xsl:apply-templates select="@*"/>
<!--
call a template to construct the naming policy and place
the result in a
variable in order to construct the CN.
-->
<xsl:variable name="object-name">
<xsl:call-template name="create-object-name"/>
</xsl:variable>
<!--
set the cn for the NDS Object
-->
<add-attr attr-name="CN">
<value type="string">
<xsl:value-of select="$object-name"/>
</value>
</add-attr>
<!--
copy the rest of the attributes through
-->
<xsl:apply-templates select="* | comment() |
processing-instruction() | text()"/>
</xsl:copy>
</xsl:template>
<!--
################################################## #################
get-stripped-name will remove extraneous white-space, generational
qualifier
values of 'Jr', 'II' and 'III', and will remove "'", "-", and "%"
characters from a passed
in name
################################################## #################
-->
<xsl:template name="get-stripped-name">
<xslaram name="inname"/>
<!-- first normalize the white-space characters -->
<xsl:variable name="normalizedName"
select="normalize-space($inname)"/>
<!-- Strip any Generational Qualifiers -->
<xsl:variable name="stripQualifier">
<xsl:choose>
<xsl:when test="contains($normalizedName, '
Jr')">
<xsl:value-of
select="substring-before($normalizedName, ' Jr')"/>
</xsl:when>
<xsl:when test="contains($normalizedName, '
II')">
<xsl:value-of
select="substring-before($normalizedName, ' II')"/>
</xsl:when>
<xsl:when test="contains($normalizedName, '
III')">
<xsl:value-of
select="substring-before($normalizedName, ' III')"/>
</xsl:when>
<xsltherwise>
<xsl:value-of select="$normalizedName"/>
</xsltherwise>
</xsl:choose>
</xsl:variable>
<!-- Strip a "-" (dash), "'" (apostrophe), "," (comma), "."
(period), or "%" (percent) character -->
<xsl:variable name="stripSpecials">
<xsl:choose>
<!-- This is a test for the apostrophe character
-->
<xsl:when test="contains($stripQualifier,
&quot;&apos;&quot">
<xsl:value-of
select="concat(substring-before($stripQualifier, &quot;&apos;&quot,
substring-after($stripQualifier, &quot;&apos;&quot)"/>
</xsl:when>
<xsl:when test="contains($stripQualifier, '-')">
<xsl:value-of
select="concat(substring-before($stripQualifier, '-'),
substring-after($stripQualifier, '-'))"/>
</xsl:when>
<xsl:when test="contains($stripQualifier, ',')">
<xsl:value-of
select="concat(substring-before($stripQualifier, ','),
substring-after($stripQualifier, ','))"/>
</xsl:when>
<xsl:when test="contains($stripQualifier, '.')">
<xsl:value-of
select="concat(substring-before($stripQualifier, '.'),
substring-after($stripQualifier, '.'))"/>
</xsl:when>
<xsl:when test="contains($stripQualifier, '%')">
<xsl:value-of
select="concat(substring-before($stripQualifier, '%'),
substring-after($stripQualifier, '%'))"/>
</xsl:when>
<xsltherwise>
<xsl:value-of select="$stripQualifier"/>
</xsltherwise>
</xsl:choose>
</xsl:variable>
<xsl:value-of select="$stripSpecials"/>
</xsl:template>
<!--
################################################## #################
create-object-name creates a name for the user object and places the
result in a result tree fragment
first naming policy is first letter first name concatenated with surname

all set to uppercase
################################################## #################
-->
<xsl:template name="create-object-name">
<xsl:variable name="given-name">
<xsl:call-template name="get-stripped-name">
<xsl:with-param name="inname">
<xsl:value-of
select="add-attr[@attr-name = 'Given Name']/value"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="surname">
<xsl:call-template name="get-stripped-name">
<xsl:with-param name="inname">
<xsl:value-of
select="add-attr[@attr-name = 'Surname']/value"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="prefix"
select="substring($given-name,1,1)"/>
<xsl:variable name="ucase"
select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz
'"/>
<!-- Original: <xsl:variable name="object-name"
select="concat(translate($prefix,$lcase,$ucase),tr anslate($surname,$lcase,$ucase))"/>
-->
<!-- build an object name that is exactly seven characters -
right padded with zeros and a 1 as needed, or truncated if too long -->
<xsl:variable name="object-name1"
select="concat(translate($prefix,$lcase,$ucase),tr anslate($surname,$lcase,$ucase))"/>
<xsl:variable name="object-name">
<value>
<xsl:choose>
<xsl:when
test="string-length($object-name1) >= 7">
<xsl:value-of
select="substring($object-name1,1,7)"/>
</xsl:when>
<xsltherwise>
<xsl:value-of
select="substring(concat(substring(concat($object-name1,'0000000'),1,6),'1'),1,7)"/>
</xsltherwise>
</xsl:choose>
</value>
</xsl:variable>
<!--
execute a query and check to see if name already exists in NDS
-->
<xsl:variable name="exists">
<xsl:call-template name="query-object-name">
<xsl:with-param name="object-name"
select="$object-name"/>
</xsl:call-template>
</xsl:variable>
<!--
if exists, then try second naming policy, else return result
-->
<xsl:choose>
<xsl:when test="$exists != ''">
<xsl:call-template
name="create-object-name-fallback"/>
</xsl:when>
<xsltherwise>
<xsl:value-of select="$object-name"/>
</xsltherwise>
</xsl:choose>
</xsl:template>
<!--
################################################## #################
create-object-name-fallback recursively tries a name created by
concatenating the surname and a count until NDS doesn't find
the name. There is a danger of infinite recursion, but only if
there is a bug in NDS
third naming policy is first letter first name concatenated with surname
and a count
all set to uppercase
################################################## #################
-->
<xsl:template name="create-object-name-fallback">
<xslaram name="count" select="1"/>
<xsl:variable name="given-name">
<xsl:call-template name="get-stripped-name">
<xsl:with-param name="inname">
<xsl:value-of
select="add-attr[@attr-name = 'Given Name']/value"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="surname">
<xsl:call-template name="get-stripped-name">
<xsl:with-param name="inname">
<xsl:value-of
select="add-attr[@attr-name = 'Surname']/value"/>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="prefix"
select="substring($given-name,1,1)"/>
<xsl:variable name="ucase"
select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'"/>
<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz
'"/>
<!-- Original: <xsl:variable name="object-name"
select="concat(translate($prefix,$lcase,$ucase),tr anslate($surname,$lcase,$ucase),$count)"/>
-->
<!-- build an object name that is exactly seven characters -
right padded with zeros and a 1 as needed, or truncated if too long -->
<xsl:variable name="object-name">
<xsl:choose>
<xsl:when test="$count &lt;= 9">
<xsl:value-of
select="substring(concat(substring(concat(concat(t ranslate($prefix,$lcase,$ucase),translate($surname ,$lcase,$ucase)),'0000000'),1,6),$count),1,7)"/>
</xsl:when>
<xsl:when test="$count > 9 and $count &lt;= 99">
<xsl:value-of
select="substring(concat(substring(concat(concat(t ranslate($prefix,$lcase,$ucase),translate($surname ,$lcase,$ucase)),'0000000'),1,5),$count),1,7)"/>
</xsl:when>
<xsl:when test="$count > 99 and $count &lt;=
999">
<xsl:value-of
select="substring(concat(substring(concat(concat(t ranslate($prefix,$lcase,$ucase),translate($surname ,$lcase,$ucase)),'0000000'),1,4),$count),1,7)"/>
</xsl:when>
<xsl:when test="$count > 999 and $count &lt;=
9999">
<xsl:value-of
select="substring(concat(substring(concat(concat(t ranslate($prefix,$lcase,$ucase),translate($surname ,$lcase,$ucase)),'0000000'),1,3),$count),1,7)"/>
</xsl:when>
<xsltherwise>
<xsl:value-of
select="substring(concat(substring(concat(concat(t ranslate($prefix,$lcase,$ucase),translate($surname ,$lcase,$ucase)),'0000000'),1,2),$count),1,7)"/>
</xsltherwise>
</xsl:choose>
</xsl:variable>
<!--
execute query and see if object name exists in NDS
-->
<xsl:variable name="exists">
<xsl:call-template name="query-object-name">
<xsl:with-param name="object-name"
select="$object-name"/>
</xsl:call-template>
</xsl:variable>
<!--
if exists, then try again recursively, else return result
-->
<xsl:choose>
<xsl:when test="$exists != ''">
<xsl:call-template
name="create-object-name-fallback">
<xsl:with-param name="count"
select="$count + 1"/>
</xsl:call-template>
</xsl:when>
<xsltherwise>
<xsl:value-of select="$object-name"/>
</xsltherwise>
</xsl:choose>
</xsl:template>
<!--
################################################## #################
query object name queries NDS for the passed object-name. Ideally, this
would
not depend on "CN": to do this, add another parameter that is the name
of the
naming attribute.
################################################## #################
-->
<xsl:template name="query-object-name">
<xslaram name="object-name"/>
<!--
build an xds query as a result tree fragment
-->
<xsl:variable name="query">
<nds dtdversion="1.0" ndsversion="8.5">
<input>
<query>
<search-class
class-name="{ancestor-or-self::add/@class-name}"/>
<!--
NOTE: depends on CN being the
naming attribute
-->
<search-attr attr-name="CN">
<value>
<xsl:value-of
select="$object-name"/>
</value>
</search-attr>
<!--
put an empty read attribute in
so that we don't get the whole object back
-->
<read-attr/>
</query>
</input>
</nds>
</xsl:variable>
<!--
query NDS
-->
<xsl:variable name="result"
select="query:query($destQueryProcessor,$query)"/>
<xsl:value-of select="$result//instance/@class-name"/>
</xsl:template>
<!--
################################################## #################
copy through everything we don't want to alter
################################################## #################
-->
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
</xsl:transform>


---------------------------------------------------------------------------
David Gersic dgersic_@_niu.edu

I'm tired of receiving rubbish in my mailbox, so the E-mail address is
munged to foil the junkmail bots. Humans will figure it out on their own.