DITA XML elements with class attribute

Post here questions and problems related to editing and publishing DITA content.
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

DITA XML elements with class attribute

Post by eloralon »

Hello,

I have just started using oXygen for DITA content editing and was wondering how to make it generate by default all <p>, <li> or <i> elements with a class attribute like:

Code: Select all

<p class="- topic/p "> 
<li class="- topic/li ">
and

Code: Select all

<i class="+ topic/ph hi-d/i ">
.

These attributes are used for further manipulation of the content during transformation.

Thanks
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: DITA XML elements with class attribute

Post by adrian »

Hello,

Class attributes are usually only necessary when using a DITA customization. You don't have to explicitly specify the class attributes for the default DITA implementation. The class attributes are already specified as default value attributes in the DITA DTDs and are taken into consideration by the transformation.

For this to work, you nee to have a DITA DOCTYPE declaration in the XML file. If you do, you should see the default values of the class attributes for each element in the Attributes view in Oxygen.
The value of default attributes is represented italic/gray in the Attributes view.

e.g. for a DITA topic

Code: Select all

<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
The attributes view looks like this when the caret is inside a paragraph element(p) which doesn't specify the class attribute.
Image
Note the default value for class '- topic/p '.

Let us know if you really need to specify these attributes disregarding the default values from the DTD.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

Re: DITA XML elements with class attribute

Post by eloralon »

Thanks Adrian for your reply,

I see that by default the class attribute is already present on the <p> element but does not get created in the content.

I will definitely need the <p> element with the class attribute.

Please let me know how to activate it by default whenever a new paragraph is created.

Thanks

Loralon
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: DITA XML elements with class attribute

Post by adrian »

This isn't something that you can simply activate. To accomplish this there are significant changes that are necessary in the DTDs and Oxygen's Author actions.
To be honest, it's a huge task and I don't see the amount of work involved to accomplish this resulting in any real benefit.


A simpler way to go about this would be to post-process the file afterwards with an XML stylesheet and set the class attributes for the necessary elements.


If I may ask, why do you need these attributes in the content?
Maybe I've mentioned this before, but they are not necessary there. The fact that they are already in the DTD as default attribute values is enough for the transformations to work correctly.
Aren't you using the DITA-OT transformations?

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

Re: DITA XML elements with class attribute

Post by eloralon »

Thanks Adrian,

I believe the suggestion for xslt post-processing is the best for now. I only need the class attribute because it is used for further processing of the content when doing transformation to PDF via DITA OT.

If you don't mind can you provide a sample xslt template that can be used for the purpose?

Loralon.
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: DITA XML elements with class attribute

Post by adrian »

I'll try to come up with a stylesheet that does this for you, if you insist.

But I still think you've missed the point of the class attributes. They are meant for DITA specializations, they are not necessary nor are they recommended in the content. The DITA OT transformation stylesheets pick up the class attributes declared in the DTD(referred in the DOCTYPE from each DITA XML document).

Here's a link to the DITA specs, if you want an official source:
http://docs.oasis-open.org/dita/v1.2/os ... l#classatt

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
eloralon
Posts: 38
Joined: Thu Oct 28, 2010 5:10 pm

Re: DITA XML elements with class attribute

Post by eloralon »

Thanks Adrian,

I did not mean to insist on this, I perfectly agree with you on the official specifications for DITA XML.

Thank a lot for your time and help.

Loralon
kaeferc
Posts: 1
Joined: Wed Mar 06, 2013 3:35 am

Re: DITA XML elements with class attribute

Post by kaeferc »

Adrian, you mentioned that it can be done - including the class attribute in the saved DITA file. I do really need that and would love to know what needs to be done so that I can include the attribute.
adrian
Posts: 2850
Joined: Tue May 17, 2005 4:01 pm

Re: DITA XML elements with class attribute

Post by adrian »

Hello,

If you want all attributes (including class) to be pulled from the DTD into the DITA file, all you need is a copy stylesheet:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"/>
<!-- Match document -->
<xsl:template match="/">
<xsl:apply-templates mode="copy" select="."/>
</xsl:template>
<!-- Deep copy template -->
<xsl:template match="*|text()|@*" mode="copy">
<xsl:copy>
<xsl:apply-templates mode="copy" select="@*"/>
<xsl:apply-templates mode="copy"/>
</xsl:copy>
</xsl:template>
<!-- Handle default matching -->
<xsl:template match="*"/>
</xsl:stylesheet>
Note however that when applying this against the DITA document, the DOCTYPE, comments and processing instructions (including the Oxygen change tracking markers) will be stripped.
To include the DOCTYPE you can either manually re-add it, or change the xsl:output to include the appropriate public/system IDs.
e.g. for a DITA Topic

Code: Select all

<xsl:output method="xml" doctype-public="-//OASIS//DTD DITA Topic//EN" doctype-system="http://docs.oasis-open.org/dita/v1.1/OS/dtd/topic.dtd"/>
Also, if you want to strip some of the attribute pulled from the DTD, you can simply add another xsl:template that matches them, but does not forward them to the output.

e.g. This strips down the ditaarch:DITAArchVersion and domains attributes.

Code: Select all

<xsl:template match="@ditaarch:DITAArchVersion|@domains" mode="copy"/>
Let me know if you need something more specific.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply