XSLT in batch

Post here questions and problems related to oXygen frameworks/document types.
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

XSLT in batch

Post 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
radu_pisoi
Posts: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: XSLT in batch

Post 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
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: XSLT in batch

Post 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
radu_pisoi
Posts: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: XSLT in batch

Post 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.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: XSLT in batch

Post 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
radu_pisoi
Posts: 403
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: XSLT in batch

Post 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.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
urbanrobots
Posts: 86
Joined: Sun May 03, 2015 7:34 pm
Location: San Francisco

Re: XSLT in batch

Post 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
alin
Site Admin
Posts: 268
Joined: Thu Dec 24, 2009 11:21 am

Re: XSLT in batch

Post 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
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply