Expand my Community achievements bar.

Why does XML Add on v3.8 not support DITA 1.3 base element topic/div ?

Avatar

Level 2

Issue/Query:
Why does XML Add on v3.8 not support DITA 1.3 base element topic/div? For a migrated HTML document, the target topic .dita does not have any <div> tags.

AEM Instance:
AEM 6.5 + SP7 + SP8 + XML Add On v3.8

Issue Description:
Followed the steps from Migrate XHTML documents section of the document Installation and Configuration Guide 

The .dita file that gets created after the import is stripped off of any and every <div> tags. Confirmed from the h2d.xsl that this is indeed the case.

<!-- divs: if we can base transform on a class, do so. -->
<!-- generic divs will fall through with no associated transform --><xsl:template match="div">
<xsl:template match="div">
<xsl:apply-templates select="*|text()|comment()"/>
</xsl:template> 

 Is there a planned/available hotfix to fix this issue?

@DivrajSingh  

3 Replies

Avatar

Employee

Generally in context of HTML, "div" elements are for styling purposes whereas in DITA the styling is stripped off as presentation is separated out from content when working in DITA.

With that assumption the rule has a generic implementation.

However, in your implementation if you need to enable this, you can override that rule by:

  • copying this template code to the file "/apps/fmdita/config/html2dita/h2d_extended.xsl"
  • to override add priority attribute to the xsl:template.

So, the rule in h2d_extended.xsl will look like:

<xsl:template match="div" priority="2">
<div>
  <xsl:apply-templates select="*|text()|comment()"/>
</div>
</xsl:template> 

I hope this answers your query.

Avatar

Level 2

Thanks for answering the previous query @DivrajSingh . Assigning priority to the div as suggested by you worked. I have a few follow up questions -

  • Per project requirement, I would like the custom classes associated with <div> be carried forward till the output preset generation (AEM Site in this case) as well. This is very similar to what happens for the <span> tag now. Do you have any suggestions/recommendations/sample code for this requirement?
  • Is there any restriction on the attributes supported with div ? Assuming that I allow the div tag to be carried forward in the generated dita file by modifying the h2d_extended.xsl as discussed by you above, I am curious to understand if any attribute of <div> be stripped during the conversion from HTML to Dita ?  If yes, which ones and can how can that be avoided?

Avatar

Employee

Some background before I address both the queries in detail. The publishing mechanism from DITA to AEM Sites uses a configuration "/libs/fmdita/config/elementmapping.xml" which defines rules to map dita elements/attributes to the generate sites components/properties correspondingly.

You can read more about this in the section "Customize DITA element mapping with AEM components" of Installation and Configuration Guide (page 92)

Any changes required in the elementmapping.xml should be done in following way:

  • Override the file under /apps
  • Mention path of this overridden file in the property "Override Element
    Mapping" of configuration com.adobe.fmdita.config.ConfigManager

These steps are also defined in point 4 and 5 of section "Additional Notes" Installation and Configuration Guide (page 96)

 

 

Now for the first query, by default the class attributes are propagated but they are not visible in the rendered page. To enable that, you need to add following line to the specific rule in elementmapping.xml:

<outputClassFlag>true</outputClassFlag>

The snippet in elementmapping.xml will look like:

 

<ditaelement>
	<name>div</name>
	<class>- topic/div</class>
	<componentpath>fmdita/components/dita/wrapper</componentpath>
	<type>COMPOSITE</type>
	<target>para</target>
	<wrapelement>div</wrapelement>
	<outputClassFlag>true</outputClassFlag>
</ditaelement>

NOTE: make sure you are doing the changes in the overridden file and testing after clearing the cache, as described in beginning of this post

 

 

For the second query, the attributes that are by default propagated from html to dita are "class" and "id" considering the fact that these attributes are supported in DITA as well. But if you have a case where the source HTMLs can have additional attributes which are also compliant with DITA specs then you can do following:

Step 1: add a rule in h2d_extended.xsl for getting additional/all attributes to DITA:

 

<xsl:template match="div" priority="2">
	<div>
		<xsl:copy-of select="@*" />
		<xsl:apply-templates select="*|text()|comment()"/>
	</div>
</xsl:template>

 

Step 2: add rule in element mapping for propagating these attribute/values from DITA to AEM sites component properties

 

<ditaelement>
	<name>div</name>
	<class>- topic/div</class>
	<componentpath>fmdita/components/dita/wrapper</componentpath>
	<type>COMPOSITE</type>
	<target>para</target>
	<wrapelement>div</wrapelement>
	<outputClassFlag>true</outputClassFlag>
	<attributemap>
		<attribute from="dita-attribute-name" to="desired-property-in-aem-component" />
	</attributemap>
</ditaelement>

NOTE: make sure you are doing the changes in the overridden file and testing after clearing the cache, as described in beginning of this post

 

 

I hope this addresses both of your queries.