Sort definition list of current file without resolving implicit attributes

Post here questions and problems related to editing and publishing DITA content.
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Sort definition list of current file without resolving implicit attributes

Post by xephon »

Hi,

I have a small XSLT that sorts a definition list. In a transformation scenario I defined:
  • XML URL: ${currentFileURL}
  • XSL URL: myScript.xsl
  • Output file: ${currentFileURL}
So the source file is the output file, too.

Sample Topic

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE topic PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic id="foo">
<title></title>
<body>
<dl>
<dlentry id="C">
<dt>C</dt>
<dd></dd>
</dlentry>
<dlentry id="B">
<dt>B</dt>
<dd></dd>
</dlentry>
<dlentry id="A">
<dt>A</dt>
<dd></dd>
</dlentry>
</dl>
</body>
</topic>
XSLT

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xd="http://www.oxygenxml.com/ns/doc/xsl"
exclude-result-prefixes="xs xd"
version="2.0">
<xd:doc scope="stylesheet">
<xd:desc>
<xd:p><xd:b>Created on:</xd:b> Oct 30, 2015</xd:p>
<xd:p><xd:b>Author:</xd:b> Stefan Eike</xd:p>
<xd:p></xd:p>
</xd:desc>
</xd:doc>

<xsl:output omit-xml-declaration="yes" indent="yes"
doctype-public="-//OASIS//DTD DITA Topic//EN"
doctype-system="topic.dtd"/>
<xsl:strip-space elements="*"/>

<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>

<xsl:template match="*[contains(@class,' topic/dl ')]">
<xsl:copy>
<xsl:apply-templates select="*[contains(@class,' topic/dlentry ')]">
<xsl:sort select="@id" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>

</xsl:stylesheet>
The script works, but it resolves implicit attributes:

Output

Code: Select all


<!DOCTYPE topic
PUBLIC "-//OASIS//DTD DITA Topic//EN" "topic.dtd">
<topic xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
id="foo"
ditaarch:DITAArchVersion="1.2"
domains="(topic hi-d)
(topic ut-d)
(topic indexing-d)
(topic hazard-d)
(topic abbrev-d)
(topic pr-d)
(topic sw-d)
(topic ui-d)"
class="- topic/topic ">
<title class="- topic/title "/>
<body class="- topic/body ">
<dl>
<dlentry id="A" class="- topic/dlentry ">
<dt class="- topic/dt ">A</dt>
<dd class="- topic/dd "/>
</dlentry>
<dlentry id="B" class="- topic/dlentry ">
<dt class="- topic/dt ">B</dt>
<dd class="- topic/dd "/>
</dlentry>
<dlentry id="C" class="- topic/dlentry ">
<dt class="- topic/dt ">C</dt>
<dd class="- topic/dd "/>
</dlentry>
</dl>
</body>
</topic>
How can I avoid that? Is a transformations scenario the correct way to implement a simple sort mechanism like that? How would you implement this?


Thanks and best regards,
Stefan
stefan-jung.org – Your DITA/DITA-OT XML consultant
Patrik
Posts: 280
Joined: Thu Nov 28, 2013 9:32 am
Location: Hamburg/Germany
Contact:

Re: Sort definition list of current file without resolving implicit attributes

Post by Patrik »

Hi Stefan,

to get rid of the default attributes just change the settings for your transformation scenario and disable "expand default attributes".

But doing that you would have to change the code as well since it can no more read the class attributes. E.g.

Code: Select all

<xsl:template match="dl">
<xsl:copy>
<xsl:apply-templates select="dlentry">
<xsl:sort select="@id" data-type="text"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
There is no simple way to read the default attributes in your script but keep them from beeing copied to the output

Patrik
xephon
Posts: 140
Joined: Mon Nov 24, 2014 1:49 pm
Location: Greven/Germany

Re: Sort definition list of current file without resolving implicit attributes

Post by xephon »

Hi Patrik,

herzlichen Dank, hat funktioniert.

Works as expected.

Have a nice weekend
Stefan
stefan-jung.org – Your DITA/DITA-OT XML consultant
Post Reply