Page 1 of 1

XSLT in batch

Posted: Mon Jun 06, 2016 8:02 am
by urbanrobots
Hello,

We'd like to perform some cleanup on our DITA files using XSLT. Here is the code that we'd like to run across all files in the database:

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<xsl:output method="xml" indent="yes"/>

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

<!-- Remove certain topicref attributes -->
<xsl:template match="topicref/@type[.='concept' or .='reference' or .='task']"/>
<xsl:template match="topicref/@format[.='ditamap' or .='dita']"/>
<xsl:template match="@scope[.='local']"/>
<xsl:template match="topicref/@navtitle"/>
<xsl:template match="@class"/>

<!-- Remove certain mapref attributes -->
<xsl:template match="mapref/@format[.='ditamap']"/>
<xsl:template match="mapref/@type[.='map']"/>
<xsl:template match="mapref/@navtitle"/>

<!-- Remove certain keydef attributes -->
<xsl:template match="keydef/@type[.='concept' or .='reference' or .='task']"/>
<xsl:template match="keydef/@format[.='ditamap' or .='dita']"/>
<xsl:template match="keydef/@processing-role[.='resource-only']"/>

<!-- Add image alt text element using the imate alt attribute -->
<xsl:template match="image">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
<alt>
<xsl:value-of select="@alt"/>
</alt>

</xsl:copy>
</xsl:template>

<!-- Remove image alt attribute -->
<xsl:template match="image/@alt"/>
</xsl:stylesheet>
Fortunately, in Oxygen we can create a project and then run a transform on all files in a folder pretty easily. I set the XML URL to ${currentFileURL} and it shows the results fine in the resources tab. The issue is that the files are not actually being modified.

So, to run the XSLT code and actually modify the files, what setting or coded content are we missing??

Thanks for your time.

Take care,
- Nick

Re: XSLT in batch

Posted: Mon Jun 06, 2016 4:10 pm
by radu_pisoi
urbanrobots wrote:So, to run the XSLT code and actually modify the files, what setting or coded content are we missing??
I think you should select the 'Save as' option in the 'Output' tab of the 'Edit Scenario' dialog. In the right part of the 'Save Option' radio you should specify ${cf} value which points to the current processed file.

But, the best option for your use case is to create an XML Refactoring operation that will use your XSLT stylesheet.
The advantages of this approach are:
* you can preview the modifications before you apply them;
* The DOCTYPE will be preserved.
* The DTD entities will be preserved as they are in the original document when the document is saved.
*The attribute values will be kept in their original form without being normalized. The spaces between attributes are preserved. Basically, the spaces are lost by a regular XML serialization since they are not considered important.

You can read more about how to create custom XML Refactoring operations in our user manual:
https://www.oxygenxml.com/doc/versions/ ... ons-1.html

Re: XSLT in batch

Posted: Sat Jun 11, 2016 2:59 am
by urbanrobots
Awesome! The XML Refactoring Tool is exactly what I need. Thanks, Radu.

It works fine when I need to update local files. How do I run it on a WebDAV connection? Seems like this isn't an available option for the XML Refactoring Tool nor for a Project configuration.

Thanks for your help.

Take care,
- Nick

Re: XSLT in batch

Posted: Mon Jun 13, 2016 12:03 pm
by radu_pisoi
Sorry, the XML Refactoring tool can't be run over a WebDAV connection. I will add a feature request for this.

Meanwhile, an workaround could be to map your remote data to a network drive. After that, you could link that network drive to the project and apply XML Refactoring over it.

Re: XSLT in batch

Posted: Mon Jun 13, 2016 6:40 pm
by urbanrobots
Hi Radu - Thanks a lot! This is in fact exactly what I ended up doing yesterday... just mapped a network share and it runs okay. It's a little slow and sometimes hangs at
Save affected resources...
for a very long time and you think that Oxygen may have frozen during the operation.

While running the refactoring in a batch seems to work fine, running the same XSLT on just one file removes the DTD information and adds domain info that throws a syntax error in Oxygen, so this:

Code: Select all

<!DOCTYPE map PUBLIC "-//OASIS//DTD DITA Map//EN" "map.dtd">
<map>
will change to this:

Code: Select all

<map xmlns:ditaarch="http://dita.oasis-open.org/architecture/2005/"
ditaarch:DITAArchVersion="1.3"
domains="(map mapgroup-d) (topic abbrev-d) (topic delay-d) a(props deliveryTarget) (map ditavalref-d) (map glossref-d) (topic hazard-d) (topic hi-d) (topic indexing-d) (topic markup-d) (topic pr-d) (topic relmgmt-d) (topic sw-d) (topic ui-d) (topic ut-d) (topic markup-d xml-d) ">
Any way around that?

Take care,
- Nick

Re: XSLT in batch

Posted: Tue Jun 14, 2016 8:38 am
by radu_pisoi
Hi Nick,

No, there is no way to tell to the XSLT processor to keep the DTD declaration in a normal processing.
For XML Refactoring, we make some preprocessing steps to avoid the DTD removal.

Re: XSLT in batch

Posted: Thu Jun 16, 2016 6:44 pm
by urbanrobots
Hi Radu -
Okay, no problem. Thank you.

One last question:
  • Is there a way to do the refactoring on only specific file types in a collection, such as the .ditamap files? This will improve performance.
Take care,
- Nick

Re: XSLT in batch

Posted: Fri Jun 17, 2016 10:48 am
by alin
Hello,

Yes, you can restrict the set of files on which you are applying the XML Refactoring operation. The third page of the XML Refactoring Wizard allows you to specify the scope of the operation (the input files set) and also to define a file pattern that will filter this set.

For example, if you want to include only the ditamap files, the file filter will look like this: *.ditamap .

You can read more about Scope and Filters here: https://www.oxygenxml.com/doc/ug-editor ... ments.html

Regards,
Alin