Following is an xsl code. This code prints body and image to an html
page. Body text and the name of image file name is provided in a form
by user. The problem arises when user only gives the file name of an
image and leaves the body blank ( The user is initially provided with
a form where he enters the text for the body and the file name for an
image and also fills some other fields for meta data). Please point
and fix the error out so that user can print the image only and
keeping body as null. [Entering a space as body is a temporay fix but
not the desired solution].
The code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
- <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:java="http://xml.apache.org/xslt/java"
xmlns:xalan-nodeset="http://xml.apache.org/xalan"
exclude-result-prefixes="java xalan-nodeset" version="1.0">
<xsl:output method="html" indent="yes" />
- <!-- Passed to the stylesheet from Documentum
-->
<xsl:param name="DMS_SESSION_ID" select="'default value'" />
<xsl:param name="DMS_INPUT_OBJECT_ID" />
- <!-- WPF GLOBALS
-->
<xsl:variable name="footerName" select="'Confidentiality_Footer.xml'" />
<xsl:variable name="footerPath" select="'/WebPublisher
Configuration/Content Templates/General Content'" />
- <xsl:variable name="webcabinet">
- <xsl:call-template name="retrieve-web-cabinet">
<xsl:with-param name="objId" select="$DMS_INPUT_OBJECT_ID" />
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="lang">
- <xsl:call-template name="retrieve-language">
<xsl:with-param name="objId" select="$DMS_INPUT_OBJECT_ID" />
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="xsl-name">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select object_name from dm_sysobject where i_chronicle_id
in</xsl:text>
<xsl:text>(select child_id from dm_relation where
relation_name='wcm_layout_template' and parent_id='</xsl:text>
<xsl:value-of select="$DMS_INPUT_OBJECT_ID" />
<xsl:text>')</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="cssFile">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select object_name from dm_sysobject where folder('</xsl:text>
<xsl:value-of select="$webcabinet" />
<xsl:text>/common/styles') and a_content_type = 'css'</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="docroot">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
- <!-- PLC: Changed docroot to use Web Cabinet's subject attribute...
no more hdo_config_list
-->
- <!-- <xsl:text>select h_val from hdo_config_list where
h_attr_nm = 'h_docroot' and h_app_typ <> '' </xsl:text>
<xsl:text>and h_app_typ in (select object_name from dm_folder
where r_object_id in </xsl:text>
<xsl:text>(select i_ancestor_id from dm_folder where
r_object_id in </xsl:text>
<xsl:text>(select i_folder_id from hdd_doc where r_object_id='</xsl:text>
<xsl:value-of select="$DMS_INPUT_OBJECT_ID"/>
<xsl:text>')))</xsl:text>
-->
<xsl:text>select subject from dm_sysobject where type("wcm_channel")
and r_object_id in</xsl:text>
<xsl:text>(select i_ancestor_id from dm_folder where r_object_id in</xsl:text>
<xsl:text>(select i_folder_id from dm_sysobject where r_object_id = '</xsl:text>
<xsl:value-of select="$DMS_INPUT_OBJECT_ID" />
<xsl:text>'))</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <!-- Catch-all for the HTML tags placed in the XML
by the WebPublisher template editor
-->
- <xsl:template match="*|@*|comment()|processing-instruction()|text()">
- <xsl:copy>
<xsl:apply-templates select="*|@*|comment()|processing-instruction()|text()" />
</xsl:copy>
</xsl:template>
- <xsl:template match="/module">
- <html>
- <xsl:comment>
<xsl:text>This file generated by</xsl:text>
<xsl:value-of select="$xsl-name" />
</xsl:comment>
- <head>
- <script language="Javascript">
<xsl:text>document.domain="homedepot.com";</xsl:text>
</script>
<link rel="stylesheet"
href="{$docroot}/{$lang}{$webcabinet}/common/styles/{$cssFile}"
type="text/css" />
</head>
- <body bgcolor="ffffff" leftmargin="10" topmargin="10" class="portletContent">
- <span id="mainTable">
- <xsl:if test="string(title) or string(author) or string(sourceURL)
or string(source)">
- <p>
- <xsl:if test="string(title)">
- <div class="pageTitle">
<xsl:value-of select="title" />
</div>
</xsl:if>
- <xsl:if test="string(author)">
- <span class="author">
<xsl:value-of select="author" />
</span>
<br />
</xsl:if>
- <xsl:choose>
- <xsl:when test="string(sourceURL)">
- <span class="source">
- <a href="{sourceURL}">
<xsl:value-of select="source" />
</a>
</span>
<br />
</xsl:when>
- <xsl:when test="string(source)">
- <span class="source">
<xsl:value-of select="source" />
</span>
<br />
</xsl:when>
</xsl:choose>
</p>
</xsl:if>
- <xsl:if test="anchorLinks='Y'">
- <ul>
- <xsl:for-each select="//subheader[string(normalize-space(text()))]">
- <li>
- <a href="#{position()}">
<xsl:value-of select="." />
</a>
</li>
</xsl:for-each>
</ul>
<br />
</xsl:if>
<xsl:apply-templates select="content_block" />
</span>
<xsl:call-template name="confidentiality-footer" />
</body>
</html>
</xsl:template>
- <xsl:template match="content_block">
- <xsl:if test="string(normalize-space(subheader)) != ''">
- <p class="subheading">
<a name="{position()}" />
<xsl:value-of select="subheader" />
</p>
</xsl:if>
- <!-- <xsl:copy-of select="bodyCopy/*|bodyCopy/text()"/>
-->
- <xsl:if test="bodyCopy/*[1][local-name() != 'p']">
<xsl:apply-templates select="image[position != 'Center After Text']" />
</xsl:if>
<xsl:apply-templates select="bodyCopy/*" />
- <xsl:if test="../toTopLinks='Y'">
<br />
- <xsl:if test="string(normalize-space(subheader))">
<a href="#top" class="boldtext">^ TOP ^</a>
<br />
<br />
</xsl:if>
</xsl:if>
<span style="clear: all;" />
</xsl:template>
- <xsl:template match="image">
- <!-- BUGFIX (PLC): The editor leaves in the src attrib when copying; check PI
-->
- <!-- <xsl:if test="@src != ''">
-->
- <xsl:if test="processing-instruction('dctmLink') != ''">
- <xsl:variable name="imgStyle">
- <xsl:choose>
- <xsl:when test="position = 'Center After Text'">
<xsl:text>margin: 5px;</xsl:text>
</xsl:when>
- <xsl:when test="position = 'Float Left'">
<xsl:text>float: left; margin-right: 5px; margin-bottom: 5px;</xsl:text>
</xsl:when>
- <xsl:when test="position = 'Float Right'">
<xsl:text>float: right; margin-left: 5px; margin-bottom: 5px;</xsl:text>
</xsl:when>
</xsl:choose>
</xsl:variable>
- <img src="/{$lang}{substring-after(processing-instruction('dctmEditor.src'),'selectedPath=')}"
alt="{@alt}" style="{$imgStyle}">
- <xsl:if test="@width != ''">
- <xsl:attribute name="width">
<xsl:value-of select="@width" />
</xsl:attribute>
</xsl:if>
- <xsl:if test="@height != ''">
- <xsl:attribute name="height">
<xsl:value-of select="@height" />
</xsl:attribute>
</xsl:if>
</img>
</xsl:if>
</xsl:template>
- <xsl:template match="p">
- <p>
- <xsl:if test="position() = 1">
<xsl:apply-templates select="../../image[position != 'Center After Text']" />
</xsl:if>
<xsl:apply-templates select="*|text()" />
</p>
- <xsl:if test="position() = last()">
- <p align="center">
<xsl:apply-templates select="../../image[position = 'Center After Text']" />
</p>
</xsl:if>
</xsl:template>
- <!-- Removed to fix relative links jhv 7/704
<xsl:template match="table">
<xsl:if test="position() = 1">
<xsl:apply-templates
select="ancestor::content_block/image[position != 'Center After
Text']"/>
</xsl:if>
<xsl:copy-of select="."/>
</xsl:template>
-->
- <!-- PLC: Reinstated and modified to apply further templates inside
the table 7/22/04
-->
- <xsl:template match="table">
- <!-- Removed in favor of image handling in content_block
-->
- <!-- <xsl:if test="position() = 1">
<xsl:apply-templates
select="ancestor::content_block/image[position != 'Center After
Text']"/>
</xsl:if>
-->
- <xsl:copy>
<xsl:apply-templates select="*|@*|text()" />
</xsl:copy>
</xsl:template>
- <xsl:template match="li">
- <xsl:copy>
<xsl:apply-templates select="@*|text()|*[local-name() != 'p']|p/*|p/text()" />
</xsl:copy>
</xsl:template>
- <!-- Template to get each link's output format if it will be sent
to cache with a different file extension
-->
- <xsl:template match="a">
- <xsl:choose>
- <xsl:when test="starts-with(@href,'http')">
- <xsl:call-template name="create-link">
<xsl:with-param name="url" select="@href" />
- <xsl:with-param name="text">
<xsl:copy-of select="*|text()" />
</xsl:with-param>
</xsl:call-template>
</xsl:when>
- <xsl:otherwise>
<xsl:variable name="linkLocation" select="concat($webcabinet, @href)" />
- <xsl:variable name="fileName">
- <xsl:call-template name="substring-after-last">
<xsl:with-param name="input" select="$linkLocation" />
<xsl:with-param name="marker" select="'/'" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="folderPath"
select="substring-before($linkLocation,concat('/',$fileName))" />
- <xsl:call-template name="create-documentum-link">
<xsl:with-param name="location" select="$linkLocation" />
- <xsl:with-param name="object_id">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select r_object_id from dm_sysobject where FOLDER('</xsl:text>
<xsl:value-of select="$folderPath" />
<xsl:text>') and object_name = '</xsl:text>
<xsl:value-of select="$fileName" />
<xsl:text>'</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:with-param>
- <xsl:with-param name="text">
<xsl:copy-of select="*|text()" />
</xsl:with-param>
<xsl:with-param name="output" select="'html'" />
</xsl:call-template>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <xsl:template name="create-documentum-link">
<xsl:param name="object_id" />
<xsl:param name="location" />
- <!-- The folderpath and object name
-->
<xsl:param name="output" />
<xsl:param name="text" />
<xsl:param name="external" select="'false'" />
<xsl:param name="image" select="''" />
<xsl:param name="urlParms" select="''" />
<xsl:param name="appendSessionID" select="'false'" />
- <xsl:variable name="targetType">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select object_name from dm_sysobject (all) where
r_object_id in</xsl:text>
<xsl:text>(select child_id from dm_relation where
relation_name='wcm_doc_template' and parent_id='</xsl:text>
<xsl:value-of select="$object_id" />
<xsl:text>')</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="confidLevel">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select h_scty from hdd_doc where r_object_id = '</xsl:text>
<xsl:value-of select="$object_id" />
<xsl:text>'</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:choose>
- <xsl:when test="starts-with($targetType,'External_Target')">
- <xsl:call-template name="create-external-target-link">
<xsl:with-param name="output" select="$output" />
<xsl:with-param name="object_id" select="$object_id" />
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="external" select="$external" />
<xsl:with-param name="image" select="$image" />
<xsl:with-param name="urlParms" select="$urlParms" />
<xsl:with-param name="appendSessionID" select="$appendSessionID" />
</xsl:call-template>
</xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="($confidLevel = 'Confidential') or ($confidLevel = 'Private')">
- <!-- HTML cannot use the SCAI prefix from the Portlet; just put out the text
-->
<xsl:copy-of select="$text" />
</xsl:when>
- <xsl:when test="$output = 'xml'">
- <xsl:call-template name="create-thd-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="url" select="$location" />
<xsl:with-param name="external" select="$external" />
<xsl:with-param name="image" select="$image" />
<xsl:with-param name="urlParms" select="$urlParms" />
<xsl:with-param name="appendSessionID" select="'false'" />
<xsl:with-param name="object_id" select="$object_id" />
</xsl:call-template>
</xsl:when>
- <xsl:when test="$output = 'html'">
- <xsl:call-template name="create-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="url" select="$location" />
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <xsl:template name="create-external-target-link">
<xsl:param name="output" />
<xsl:param name="object_id" />
<xsl:param name="text" />
<xsl:param name="external" select="'false'" />
<xsl:param name="image" select="''" />
<xsl:param name="urlParms" select="''" />
<xsl:param name="appendSessionID" select="'false'" />
- <xsl:variable name="results">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select r_object_id from dm_sysobject where r_object_id = '</xsl:text>
<xsl:value-of select="$object_id" />
<xsl:text>'</xsl:text>
</xsl:with-param>
<xsl:with-param name="getContent" select="true()" />
</xsl:call-template>
</xsl:variable>
<xsl:variable name="type"
select="xalan-nodeset:nodeset($results)/xdql/object/content/module/type"
/>
<xsl:variable name="appCode"
select="xalan-nodeset:nodeset($results)/xdql/object/content/module/appCode"
/>
<xsl:variable name="url"
select="xalan-nodeset:nodeset($results)/xdql/object/content/module/url"
/>
<xsl:variable name="page"
select="xalan-nodeset:nodeset($results)/xdql/object/content/module/page"
/>
- <xsl:choose>
- <xsl:when test="$output = 'xml'">
- <xsl:choose>
- <xsl:when test="$type = 'Application'">
- <xsl:call-template name="create-thd-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="url" select="concat($appCode, $url)" />
<xsl:with-param name="external" select="$external" />
<xsl:with-param name="image" select="$image" />
<xsl:with-param name="urlParms" select="$urlParms" />
<xsl:with-param name="appendSessionID" select="$appendSessionID" />
<xsl:with-param name="object_id" select="$object_id" />
</xsl:call-template>
</xsl:when>
- <xsl:when test="$type = 'Portal Page'">
- <xsl:call-template name="create-thd-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="page" select="$page" />
<xsl:with-param name="external" select="$external" />
<xsl:with-param name="image" select="$image" />
<xsl:with-param name="urlParms" select="$urlParms" />
<xsl:with-param name="appendSessionID" select="$appendSessionID" />
<xsl:with-param name="object_id" select="$object_id" />
</xsl:call-template>
</xsl:when>
- <xsl:when test="$type = 'Generic URL'">
- <xsl:call-template name="create-thd-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="url" select="$url" />
<xsl:with-param name="external" select="$external" />
<xsl:with-param name="image" select="$image" />
<xsl:with-param name="urlParms" select="$urlParms" />
<xsl:with-param name="appendSessionID" select="$appendSessionID" />
<xsl:with-param name="object_id" select="$object_id" />
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:when>
- <xsl:otherwise>
- <xsl:choose>
- <xsl:when test="$type = 'Application'">
- <!-- Illegal link, just output the text
-->
<xsl:copy-of select="$text" />
</xsl:when>
- <xsl:when test="$type = 'Portal Page'">
- <!-- Illegal link, just output the text
-->
<xsl:copy-of select="$text" />
</xsl:when>
- <xsl:when test="$type = 'Generic URL'">
- <xsl:call-template name="create-link">
<xsl:with-param name="text" select="$text" />
<xsl:with-param name="url" select="$url" />
</xsl:call-template>
</xsl:when>
</xsl:choose>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <xsl:template name="create-link">
- <!-- These params apply to all links
-->
<xsl:param name="url" />
<xsl:param name="text" />
- <xsl:choose>
- <xsl:when test="starts-with($url,'http') and contains($url,'GetContentServlet')">
- <a href="{$url}">
<xsl:copy-of select="$text" />
</a>
</xsl:when>
- <xsl:when test="starts-with($url,'http')">
- <a href="#">
- <xsl:attribute name="onclick">
<xsl:text>window.open('</xsl:text>
<xsl:value-of select="$url" />
<xsl:text>', 'ContentWindow',
'height=600,width=800,menubar=yes,location=no,resizable=yes,toolbar=yes,scrollbars=yes,status=yes')</xsl:text>
</xsl:attribute>
<xsl:copy-of select="$text" />
</a>
</xsl:when>
- <xsl:when test="not(contains($url,'.htm')) and not(contains($url,'.xml'))">
- <a href="#">
- <xsl:attribute name="onclick">
<xsl:text>window.open('/</xsl:text>
<xsl:value-of select="concat($lang,$url)" />
<xsl:text>', 'ContentWindow',
'height=600,width=800,menubar=no,location=no,resizable=yes,toolbar=no,scrollbars=yes,status=no')</xsl:text>
</xsl:attribute>
<xsl:copy-of select="$text" />
</a>
</xsl:when>
- <xsl:otherwise>
- <a href="/{$lang}{$url}">
<xsl:copy-of select="$text" />
</a>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <!-- Standard XDQL Query Template
-->
- <xsl:template name="query">
<xsl:param name="sDQLString" />
<xsl:param name="getContent" select="false()" />
<xsl:variable name="xdqlSelect" select="$sDQLString" />
<xsl:variable name="dql" select="string($xdqlSelect)" />
<xsl:variable name="xdql"
select="java:com.documentum.xml.xdql.DfXmlQuery.new()" />
<xsl:variable name="init" select="java:init($xdql)" />
<xsl:variable name="setDql" select="java:setDql($xdql,$dql)" />
<xsl:variable name="setContentEncoding"
select="java:setContentEncoding($xdql,'dom')" />
<xsl:variable name="setContentFormat"
select="java:setContentFormat($xdql,'xml')" />
<xsl:variable name="setRootNode" select="java:setRootNode($xdql,'xdql')" />
<xsl:variable name="Repeatingasnested"
select="java:setRepeatingAsNested($xdql,false())" />
<xsl:variable name="includeContent"
select="java:includeContent($xdql,$getContent)" />
<xsl:variable name="execute"
select="java:execute($xdql,'DF_READ_QUERY',$DMS_SESSION_ID)" />
<xsl:variable name="results" select="java:getXMLDOM($xdql)" />
<xsl:copy-of select="$results" />
</xsl:template>
- <!-- Reusable function to retrieve the substring after the last
occurrence of a specific string
-->
- <xsl:template name="substring-after-last">
<xsl:param name="input" />
<xsl:param name="marker" />
<xsl:variable name="next" select="substring-after($input,$marker)" />
- <xsl:choose>
- <xsl:when test="contains($next, $marker)">
- <xsl:call-template name="substring-after-last">
<xsl:with-param name="input" select="$next" />
<xsl:with-param name="marker" select="$marker" />
</xsl:call-template>
</xsl:when>
- <xsl:otherwise>
<xsl:value-of select="$next" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
- <!-- Get the folder path for the Web Cabinet
-->
- <xsl:template name="retrieve-web-cabinet">
<xsl:param name="objId" />
- <xsl:variable name="results">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select r_folder_path, r_object_id from dm_folder where
r_object_id in</xsl:text>
<xsl:text>(select i_folder_id from hdd_doc where r_object_id = '</xsl:text>
<xsl:value-of select="$objId" />
<xsl:text>')</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="folderPath"
select="concat(xalan-nodeset:nodeset($results)/xdql/object/r_folder_path,
'/')" />
<xsl:value-of select="concat( '/',
substring-before(substring-after($folderPath,'/'), '/') )" />
</xsl:template>
- <!-- Get the language code of the object in question
-->
- <xsl:template name="retrieve-language">
<xsl:param name="objId" />
- <xsl:variable name="results">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select language_code from dm_sysobject where r_object_id =
'</xsl:text>
<xsl:value-of select="$objId" />
<xsl:text>'</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
<xsl:value-of select="xalan-nodeset:nodeset($results)/xdql/object/language_code"
/>
</xsl:template>
- <xsl:template name="confidentiality-footer">
- <xsl:variable name="confidLevel">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select h_scty from hdd_doc where r_object_id = '</xsl:text>
<xsl:value-of select="$DMS_INPUT_OBJECT_ID" />
<xsl:text>'</xsl:text>
</xsl:with-param>
</xsl:call-template>
</xsl:variable>
- <xsl:variable name="footerFile">
- <xsl:call-template name="query">
- <xsl:with-param name="sDQLString">
<xsl:text>select r_object_id from dm_sysobject where object_name = '</xsl:text>
<xsl:value-of select="$footerName" />
<xsl:text>' and FOLDER('</xsl:text>
<xsl:value-of select="$footerPath" />
<xsl:text>')</xsl:text>
</xsl:with-param>
<xsl:with-param name="getContent" select="true()" />
</xsl:call-template>
</xsl:variable>
<xsl:copy-of select="xalan-nodeset:nodeset($footerFile)/xdql/object/content/module/footer[@level
= $confidLevel]/*" />
</xsl:template>
</xsl:stylesheet> |