hi,

got the following problem:

feeding a simple set of personal information to an external application
in the form of a comma-separated list of values.
three operations defined: add,delete,rename
add and delete have (simplified) a surname and the type of operation
(see xml-example below) rename has old and new name, fortunately with
interchanged positions of 'new_sn' and 'old_sn'. i do definitely not
want to get that corrected in the application (i want this to happen in
the next days, not 2017, Q3 or something ..), but my xsl-fu is not
strong enough to get the output.xsl to properly distinguish between
those two cases. played a bit around monkey-style, and read a bit about
xsl, but i absolutely would like to avoid really having to look in these
(dark) places -- asking you to help me out ... please ...

so, if the operation is 'rename', make old_sn;operation;new_sn, if it is
'add|delete' create a new_sn;operation line ...

thanks for you help, florian

----------------
ADD
----------------
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Standard" version="4.0.2.0">DirXML</product>
<contact>Novell, Inc.</contact>
</source>
<input>
<instance class-name="User"
qualified-src-dn="O=myO\OU=myOU\CN=myCN"
src-dn="\myO-TREE\myO\myOU\myCN" src-entry-id="98722">
<attr attr-name="new_sn">
<value timestamp="1479910860#2"
type="string">Mueller</value>
</attr>
<attr attr-name="operation">
<value timestamp="1479910866" type="string">add</value>
</attr>
</instance>
</input>
</nds>

----------------
RENAME
----------------
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Standard" version="4.0.2.0">DirXML</product>
<contact>Novell, Inc.</contact>
</source>
<input>
<instance class-name="User"
qualified-src-dn="O=myO\OU=myOU\CN=myCN"
src-dn="\myO-TREE\myO\myOU\myCN" src-entry-id="98722">
<attr attr-name="old_sn">
<value timestamp="1479910860#2"
type="string">Mueller</value>
</attr>
<attr attr-name="operation">
<value timestamp="1479910866"
type="string">rename</value>
</attr>
<attr attr-name="new_sn">
<value timestamp="1479910866"
type="string">Mueller-Luedenscheidt</value>
</attr>
</instance>
</input>
</nds>

----------------
OUTPUT TRANSFORM STYLESHEET
----------------
<?xml version="1.0" encoding="UTF-8"?><xsl:stylesheet version="1.0"
xmlns:cmd="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsCommandProcessor"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xslaram name="srcCommandProcessor"/>
<!-- each application must fill in the name of the field that provides
the association key -->
<xsl:variable name="association-field-name" select="'Email'"/>
<!-- change the following line to change the delimiter from a comma to
any other desired delimiter -->
<xsl:variable name="delimiter" select="';'"/>
<xsl:template match="nds[input]">
<!-- only look at <add> events and <instances> apply a template for
each add transaction-->
<xsl:apply-templates select="//add|//instance"/>
</xsl:template>
<xsl:template match="nds[output]">
<xsl:copy-of select="."/>
</xsl:template>
<!-- now here's the template -->
<xsl:template match="input/add|input/instance">
<!-- create association if needed and we have enough info -->
<xsl:variable name="hasAssociation" select="string(association) !=
''"/>
<xsl:variable name="associationValue" select="*[(@attr-name =
$association-field-name)][1]/value[1]/text()"/>
<xsl:if test="not($hasAssociation) and $associationValue">
<xsl:variable name="dummy">
<add-association dest-dn="{@src-dn}"
dest-entry-id="{@src-entry-id}">
<xsl:value-of select="$associationValue"/>
</add-association>
</xsl:variable>
<xsl:variable name="dummy2" select="cmd:execute($srcCommandProcessor,
$dummy)"/>
</xsl:if>
<!-- output the fields in order -->
<xsl:call-template name="output-field">
<xsl:with-param name="field-value" select="*[(@attr-name =
'new_sn')][1]/value[1]"/>
</xsl:call-template>
<xsl:value-of select="$delimiter"/>
<xsl:call-template name="output-field">
<xsl:with-param name="field-value" select="*[(@attr-name =
'operation')][1]/value[1]"/>
</xsl:call-template>
<xsl:value-of select="$delimiter"/>
<xsl:with-param name="field-value" select="*[(@attr-name =
'old_sn')][1]/value[1]"/>
</xsl:call-template>
<xsl:value-of select="$delimiter"/>
<!-- finish the record with a newline -->
<!-- uncomment next line to have DOS style end of line (0D0A),
otherwise just 0A -->
<!-- <xsl:value-of select="'&#x0D;'"/> -->
<xsl:value-of select="&apos;&#xa;&apos;"/>
</xsl:template>
<xsl:template name="output-field">
<xslaram name="field-value"/>
<xsl:choose>
<xsl:when test="contains($field-value, $delimiter)">
<!-- if the field value contains a delimiter, then enclose in quotes
-->
<xsl:text>"</xsl:text>
<xsl:value-of select="$field-value"/>
<xsl:text>"</xsl:text>
</xsl:when>
<xsltherwise>
<!-- otherwise output it raw -->
<xsl:value-of select="$field-value"/>
</xsltherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>


--
florianz
------------------------------------------------------------------------
florianz's Profile: https://forums.netiq.com/member.php?userid=309
View this thread: https://forums.netiq.com/showthread.php?t=56961