[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Issue processing heterogeneous DITA files
Hi there, I've encountered a number of use cases recently in which I need to apply identity transformations to directories full of heterogeneous DITA files, i.e. dirs full of topic, task, concept, reference, or various specializations of them. The use cases range from tweaking href/conref paths to account for new/different CMS locations, to cleaning up unreferenced IDs, to modifying the structure of certain elements to support new domain specializations, etc. I'm using Ant version 1.7.1 to pass the source files to Saxon 9. The problem I've run into involves figuring out the required document type of the result document at runtime. I had assumed I could use something like this: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:variable name="publicID"> <xsl:choose> <xsl:when test="/topic"> <xsl:value-of select="'-//OASIS//DTD DITA Topic//EN'"/> </xsl:when> <!-- ....etc. for all DITA document types --> <xsl:otherwise> <xsl:value-of select="'-//OASIS//DTD DITA Composite//EN'"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="systemID"> <xsl:choose> <xsl:when test="/topic"> <xsl:value-of select="'topic.dtd'"/> </xsl:when> <!-- ....etc. for all DITA document types --> <xsl:otherwise> <xsl:value-of select="'ditabase.dtd'"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:output method="xml" encoding="UTF-8" indent="yes" doctype-public="{$publicID}" doctype-system="{$systemID}"/> <xsl:template match="/"> <xsl:apply-templates/> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- More specific templates follow here --> </xsl:stylesheet> However, once I saw the result... <!DOCTYPE topic PUBLIC "{$publicID}" "{$systemID}"> ...etc. ...I consulted the XSLT 2.0 Programmers reference and noted the restrictions on attribute-value templates in top-level declarations. The solution is a slightly kludgy use of named xsl:outputs, referenced by an <xsl:result-document>, as follows: <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0"> <xsl:output name="ditaTopic" method="xml" encoding="UTF-8" indent="yes" doctype-public="-//OASIS//DTD DITA Topic//EN" doctype-system="topic.dtd"/> <!-- ....etc. for all DITA document types --> <xsl:output name="ditaComposite" method="xml" encoding="UTF-8" indent="yes" doctype-public="-//OASIS//DTD DITA Composite//EN" doctype-system="ditabase.dtd"/> <xsl:param name="someOutputURI"/> <xsl:variable name="theDoctype"> <xsl:choose> <xsl:when test="/topic"> <xsl:value-of select="'ditaTopic'"/> </xsl:when> <!-- ....etc. for all DITA document types --> <xsl:otherwise> <xsl:value-of select="'ditaComposite'"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:template match="/"> <xsl:result-document format="{$theDoctype}" href="{$someOutputURI}"> <xsl:apply-templates/> </xsl:result-document> </xsl:template> <xsl:template match="@* | node()"> <xsl:copy> <xsl:copy-of select="@*"/> <xsl:apply-templates/> </xsl:copy> </xsl:template> <!-- More specific templates follow here --> </xsl:stylesheet> I find this kludgy, because it seems counterintuitive to me to use <xsl:result-document> when executing a one-to-one transformation. So I'm left wondering why the use of attribute-value templates has been restricted in this way, at least on public ID and system ID strings. The XSLT 2.0 Programmers Reference says this ensures that declaration values are constant for each run of the stylesheet, however that's exactly the result I don't want. Is there some inherent danger in allowing for attribute-value templates on @doctype-public and @doctype-system that I'm not seeing? Or was there an assumption made by the XSLT 2.0 WG that transformations will only be applied to instances of a uniform document type. Processing DITA in this fashion seems to provide a counterexample to that.... Thanks for any comments, Doug ============================= Doug Burgess Content Management Lead, UBI doug.burgess@xxxxxxx Work: 604-974-2334 Mobile: 778-840-8004 Business Objects, an SAP Company Vancouver BC Canada
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|