Page 1 of 1

Create XInclude from Selection

Posted: Thu Mar 26, 2015 5:50 pm
by steve.cuzner
Is there core product support for a feature where the user, in Author, selects an element, say a docbook chapter, and copies the selected content to a file and replaces the selection with an XInclude pointing to the newly created chapter fragment file? I would expect to find a feature like this under the refactor menu, but it doesn't seem to be there in 16.1 build 2015012213. If not it would be a great core product feature.

Re: Create XInclude from Selection

Posted: Thu Mar 26, 2015 6:10 pm
by Costin
Hello,

Unfortunately, a refactoring action similar to your request is not yet available in oXygen, even in the latest version.

However, we already have an open improvement request in this direction, logged on our internal issue/improvement tracking system, regarding the possibility to create a document or an xref/conref/xinclude.
So this will be analyzed by the development team and, if found viable, will be implemented in a future version of oXygen XML.
I have just added your comments to the improvement request.

Thank you and let us know whenever you need any assistance or information.

Kind Regards,
Costin

Re: Create XInclude from Selection

Posted: Thu Mar 26, 2015 7:10 pm
by Patrik
It's quite easy to implement a custom author action using XsltOperation.

The limits of my implementation:
- The author can't enter the filename. It is rather generated from the title.
- Thus it is limited to elements with a title element.
- It doesn't use the selectionbut takes the first suitable ancestor element from the cursor position.

Script:

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
exclude-result-prefixes="xs">

<xsl:template match="*[title]">
<xsl:message select="base-uri(.)"/>
<xsl:variable name="filename" as="xs:string"
select="concat(replace(normalize-space(title), '[^a-zA-Z0-9\-_]+', ''), '.dita')"/>
<xsl:result-document href="{resolve-uri($filename, base-uri())}">
<xsl:sequence select="."/>
</xsl:result-document>
<xsl:element name="include" namespace="http://www.w3.org/2001/XInclude">
<xsl:attribute name="href" select="$filename"/>
</xsl:element>
</xsl:template>

</xsl:stylesheet>
condition: exists(ancestor-or-self::*[title][1] except /*)
source- and targetLocation: ancestor-or-self::*[title][1]
action: replace

Note that this will overwrite any existing file with the same name without warning...

BTW: For my own document type I implemented an author action to export all top-level topics/chapters/appendixes... in seperate files and import them with xInclude. It is very handy when a file gets too big.

Regards,

Patrik