Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="UTF-8"?>
- <!--
- This stylesheet is the standard template processing
- stylesheet for use with the DirXML Manual Task Service Driver.
- -->
- <xsl:transform
- xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
- xmlns:form="http://www.novell.com/dirxml/manualtask/form"
- xmlns:query="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.manualtask.ManualTaskQueryProcessor"
- xmlns:xdsdn="http://www.novell.com/nxsl/java/com.novell.nds.dirxml.driver.XdsDN"
- exclude-result-prefixes="form query"
- version="1.0"
- >
- <xsl:strip-space elements="*"/>
- <xsl:param name="replacement-data" select="/.."/>
- <xsl:param name="queryProcessor"/>
- <!--
- match any element and construct it anew so we can add handle replacing
- attribute values with replacement token values, etc.
- -->
- <xsl:template match="*">
- <xsl:element name="{name()}">
- <!-- iterate through the attributes, looking for replacement data -->
- <xsl:apply-templates select="@*"/>
- <!-- go process any content -->
- <xsl:apply-templates select="node()"/>
- </xsl:element>
- </xsl:template>
- <xsl:template match="@*">
- <xsl:attribute name="{name()}">
- <xsl:choose>
- <xsl:when test="contains(.,'$')">
- <xsl:call-template name="replace-tokens">
- <xsl:with-param name="source" select="string(.)"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:attribute>
- </xsl:template>
- <xsl:template match="text()">
- <xsl:choose>
- <xsl:when test="contains(.,'$')">
- <xsl:call-template name="replace-tokens">
- <xsl:with-param name="source" select="string(.)"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template match="form:input[@name]">
- <xsl:variable name="items" select="$replacement-data/replacement-data/item[@name = current()/@name]"/>
- <xsl:variable name="type" select="string(@*[name() = 'type' or name() = 'TYPE'])"/>
- <xsl:variable name="use-value" select="@value = 'yes'"/>
- <xsl:for-each select="$items">
- <INPUT type="{$type}" name="{@name}">
- <xsl:choose>
- <xsl:when test="$use-value">
- <xsl:attribute name="value"><xsl:value-of select="."/></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <xsl:value-of select="."/>
- </xsl:otherwise>
- </xsl:choose>
- </INPUT>
- </xsl:for-each>
- </xsl:template>
- <xsl:template match="form:if-item-exists[@name]">
- <!--
- process content if an <item> element exists whose name attribute matches
- the name attribute of the form:if-item-exists element
- -->
- <xsl:if test="$replacement-data/replacement-data/item[@name = current()/@name]">
- <xsl:apply-templates/>
- </xsl:if>
- </xsl:template>
- <xsl:template match="form:if-multiple-items[@name]">
- <!--
- process content if more than one <item> element exists whose name attributes match
- the name attribute of the form:if-multiple-items element
- -->
- <xsl:if test="count($replacement-data/replacement-data/item[@name = current()/@name]) > 1">
- <xsl:apply-templates/>
- </xsl:if>
- </xsl:template>
- <xsl:template match="form:if-single-item[@name]">
- <!--
- process content if more than one <item> element exists whose name attributes match
- the name attribute of the form:if-multiple-items element
- -->
- <xsl:if test="count($replacement-data/replacement-data/item[@name = current()/@name]) = 1">
- <xsl:apply-templates/>
- </xsl:if>
- </xsl:template>
- <!-- create a <SELECT><OPTION/><OPTION/></SELECT> construct for an HTML form -->
- <xsl:template match="form:menu[@name]">
- <xsl:variable name="items" select="$replacement-data/replacement-data/item[@name = current()/@name]"/>
- <xsl:if test="$items">
- <SELECT name="{@name}">
- <OPTION selected="selected"><xsl:value-of select="$items[1]"/></OPTION>
- <xsl:for-each select="$items[position() > 1]">
- <OPTION><xsl:value-of select="."/></OPTION>
- </xsl:for-each>
- </SELECT>
- </xsl:if>
- </xsl:template>
- <xsl:template match="form:*">
- <!-- strip form: elements that aren't explicitly handled -->
- <xsl:apply-templates/>
- </xsl:template>
- <xsl:template name="replace-tokens">
- <xsl:param name="source"/>
- <!-- see if we have a replacement token -->
- <xsl:variable name="before" select="substring-before($source, '$')"/>
- <xsl:variable name="temp" select="substring-after($source, '$')"/>
- <xsl:variable name="token" select="substring-before($temp, '$')"/>
- <xsl:variable name="after" select="substring-after($temp, '$')"/>
- <xsl:choose>
- <xsl:when test="$token = '' and not(starts-with($temp,'$'))">
- <!-- no token, just output source string -->
- <xsl:value-of select="$source"/>
- </xsl:when>
- <xsl:otherwise>
- <!-- output text before substitution token -->
- <xsl:value-of select="$before"/>
- <!-- output substitution text -->
- <xsl:choose>
- <xsl:when test="$token = ''">
- <!-- adjacent $$, replace with $ -->
- <xsl:value-of select="'$'"/>
- </xsl:when>
- <xsl:when test="starts-with($token,'query:')">
- <xsl:call-template name="get-current-data">
- <xsl:with-param name="name" select="substring-after($token,'query:')"/>
- </xsl:call-template>
- </xsl:when>
- <xsl:otherwise>
- <xsl:call-template name="get-replacement-data">
- <xsl:with-param name="name" select="$token"/>
- </xsl:call-template>
- </xsl:otherwise>
- </xsl:choose>
- <!-- recurse to finish string -->
- <xsl:if test="$after != ''">
- <xsl:call-template name="replace-tokens">
- <xsl:with-param name="source" select="$after"/>
- </xsl:call-template>
- </xsl:if>
- </xsl:otherwise>
- </xsl:choose>
- </xsl:template>
- <xsl:template name="get-replacement-data">
- <xsl:param name="name"/>
- <xsl:value-of select="$replacement-data/replacement-data/item[@name = $name]"/>
- </xsl:template>
- <xsl:template name="get-current-data">
- <xsl:param name="name"/>
- <xsl:variable name="association">
- <xsl:call-template name="get-replacement-data">
- <xsl:with-param name="name" select="'association'"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="src-dn">
- <xsl:call-template name="get-replacement-data">
- <xsl:with-param name="name" select="'src-dn'"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="src-entry-id">
- <xsl:call-template name="get-replacement-data">
- <xsl:with-param name="name" select="'src-entry-id'"/>
- </xsl:call-template>
- </xsl:variable>
- <xsl:variable name="query">
- <query scope="entry">
- <!-- use entry-id value if we have it -->
- <xsl:choose>
- <xsl:when test="$src-entry-id">
- <xsl:attribute name="dest-entry-id"><xsl:value-of select="$src-entry-id"/></xsl:attribute>
- </xsl:when>
- <xsl:when test="$src-dn">
- <xsl:attribute name="dest-dn"><xsl:value-of select="$src-dn"/></xsl:attribute>
- </xsl:when>
- <xsl:otherwise>
- <association><xsl:value-of select="$association"/></association>
- </xsl:otherwise>
- </xsl:choose>
- <read-attr attr-name="{$name}"/>
- </query>
- </xsl:variable>
- <xsl:variable name="result" select="query:query($queryProcessor,$query)"/>
- <xsl:value-of select="$result//attr[@attr-name=$name]/value[1]"/>
- </xsl:template>
- <!-- strip comments from templates -->
- <xsl:template match="comment()"/>
- <!-- match everything else not handled above -->
- <xsl:template match="processing-instruction()">
- <xsl:copy/>
- </xsl:template>
- </xsl:transform>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement