[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Generating targetset structure for olinks processing
Hi there, Just to close this thread. Here is my final comment. I followed the guidelines from: http://www.docbook.org/guidelines My understanding is that docbook-apps is the mailing list appropriate for contribution outside of the docbook language itself but directly related to application manipulating docbook. Having said that, I am attaching an xsl script which generate targetset structure (I believe this is the correct name) for further olink processing. I am not attaching copyright or license since the script is based largely on a post from the xsl-list. The requirements for this script is that your build system (CMake in my case) generates a list of file to be installed (see demo.xml) <files> <file> <path>share/doc/Corporate/Training/BuildQtApplicationsWithCMake.pdf</path> </file> <file> <path>share/doc/Corporate/Training/BuildQtApplicationsWithCMake/index.html</path> </file> ... I simply copy the list of string from the 'make install' rules and then decorate them with preceding <file> and trailing </file>. This step is build system dependant (I did it using simple cmake-string manipulation). Once you have this input file. Just process it with convert_flat_tree_to_targetset_tree.xsl $ xsltproc convert_flat_tree_to_targetset_tree.xsl demo.xml This will produce a general olinkdb.xml file: <?xml version="1.0" encoding="UTF-8"?> <!-- THIS IS A GENERATED FILE DO NOT EDIT --> <targetset> <targetsetinfo> Description of this target database document, which is for the examples in olink doc. </targetsetinfo> <sitemap> <dir name="share"> <dir name="doc"> <dir name="Corporate"> <dir name="Training"> <document targetdoc="BuildQtApplicationsWithCMake" baseuri="BuildQtApplicationsWithCMake.pdf"> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="BuildQtApplicationsWithCMake.olinkdb.xml"/> </document> <dir name="BuildQtApplicationsWithCMake"> <document targetdoc="BuildQtApplicationsWithCMake" baseuri="index.html"> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="BuildQtApplicationsWithCMake.olinkdb.xml"/> </document> </dir> ... If you are still reading at that point, you should have notice that this layout imply that both the global olinkdb.xml and the individual *.olinkdb.xml (as generated by collect.xref.targets "only") should be located in the same directory, which means you have to specify an appropriate targets.filename. With this script you do not have to manually maintain neither the list of installed document, nor the path where they are located, and you leave that to the appropriate tool: your build system. I am not an XSL expert, so I cannot comment on the style of this script (portability, robustness...). I made the decision to go away from DTD and prefer XInclude, so you may have to adapt the xsl script if you cannot do XInclude. Thanks for your attention, -Mathieu Ps: This script fails when the list of filename is not alphabetically ordered, I used an intermedicate xsl:sort operation in my case, but could be done at cmake level. On Thu, Jul 8, 2010 at 7:29 PM, Bob Stayton <bobs@sagehill.net> wrote: > Hi Mathieu, > If this is about olinking, then it is relevant to this list. I didn't get > that from the original mail since it didn't mention "olink", but "targetset" > should have been a sufficient clue. > > I've thought about creating some kind of stylesheet to generate an olink > targetset structure, but I've never been able to figure out what it should > do, since everyone's requirements would be different. > > In your case, your XML example shows the output structure, but generating a > targetset structure requires knowledge of the targetdoc values and the > locations of the target data files (target.db) to be integrated into the > targetset structure. Is that information in this XML example? > > I'm also not clear about what you meant when you said: > > "where common directory need to contains multiple files, so I cannot > simply process one string at a time, but would need some kind of hash > table to find out redundancies." > > Can you provide a bit more detail? > > Bob Stayton > Sagehill Enterprises > bobs@sagehill.net > > > ----- Original Message ----- From: "Mathieu Malaterre" > <mathieu.malaterre@gmail.com> > To: "Dave Pawson" <davep@dpawson.co.uk> > Cc: <docbook-apps@lists.oasis-open.org> > Sent: Thursday, July 08, 2010 8:41 AM > Subject: Re: [docbook-apps] Generating targetset > > > On Thu, Jul 8, 2010 at 4:59 PM, Dave Pawson <davep@dpawson.co.uk> wrote: >> >> On Thu, 8 Jul 2010 11:21:41 +0200 >> Mathieu Malaterre <mathieu.malaterre@gmail.com> wrote: >> >>> Hi there, >>> >>> I am wondering if anyone had to deal with this issue before. My >>> build system is generating a list of filenames to be installed like >>> that: >>> >>> <files> >>> <file name="share/doc/Common1/Doc1/index.html"/> >>> <file name="share/doc/Common1/Doc2/index.html"/> >>> <file name="share/doc/Common2/Doc1/index.html"/> >>> <file name="share/doc/Common3/Doc1/index.html"/> >>> <file name="share/doc/Common3/Doc2/index.html"/> >>> </files> >>> >>> I would need to convert that input XML into the targetset structure, >> >> >> As I said, nothing to do with docbook, why are you asking here? >> Aren't the xsl-list answers enough for you? > > For the *exact* same reason there is a xmldepend.xsl as shipped in docbook: > > http://docbook.svn.sourceforge.net/viewvc/docbook/trunk/contrib/xsl/xmldepend/ > > I believe there should be "targetset_gen.xsl" for ease of integration > of docbook with your build system. > > This should have never been a question in XSL mailing list. BTW > docbook 4.5 only requires XSL 1.0, one cannot make it a requirement to > use XSL 2.0 just to be able to generate targetset/olinks files. > > 2cts > -- > Mathieu > > --------------------------------------------------------------------- > To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org > For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org > > > >
<?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <xsl:output method="xml" indent="yes" encoding="UTF-8"/> <!-- The goal of this XSL script is to transform a usual installation path eg.: share/doc/Corporate/Training/BuildQtApplicationsWithCMake/index.html share/doc/Corporate/Training/VirtualBox.pdf That is generally computed by build system (eg. CMake), and to convert that flat string (flat directory structure) into a full targetset structure that is used when doing olinks. This script goes over all path and detect common subdirectory so that: <dir name="share"> <dir name="doc"> <dir name="Corporate"> <dir name="Training"> <document targetdoc="BuildQtApplicationsWithCMake"/> <document targetdoc="VirtualBox"/> </dir> </dir> </dir> </dir> See for more info: * http://www.sagehill.net/docbookxsl/Olinking.html * http://www.sagehill.net/docbookxsl/OlinkVariations.html --> <!-- http://www.biglist.com/lists/xsl-list/archives/200408/msg00858.html --> <!-- Here's a set of templates that works with your example. The main template is the transformDocument template. This takes a path (an initial part of a path) and a set of items (whose paths should all start with the $path). It works out the next step in the path for the first item and from that creates a new path. Then it sorts the items into three groups: - items whose path *is* the new path, which should just be output - items whose path *starts with* the new path, which need to be processed again by this template, with the new path - items whose path *doesn't* start with the new path, which need to be processed again by this template, with the current path The result of the first two of these groups gets put within a <path> element, and the result of the third of these groups gets inserted afterwards. --> <xsl:template name="get-filename"> <xsl:param name="path"/> <xsl:choose> <xsl:when test="contains( $path, '/' )"> <xsl:call-template name="get-filename"> <xsl:with-param name="path" select="substring-after( $path, '/' )"/> </xsl:call-template> </xsl:when> <xsl:otherwise> <xsl:value-of select="$path"/> </xsl:otherwise> </xsl:choose> </xsl:template> <xsl:template name="transformDocument"> <xsl:param name="path"/> <xsl:param name="files" select="/.."/> <xsl:if test="$files"> <xsl:variable name="rest" select="substring-after($files[1]/path, concat($path, '/'))"/> <xsl:variable name="step"> <xsl:choose> <xsl:when test="contains($rest, '/')"> <xsl:value-of select="substring-before($rest, '/')"/> </xsl:when> <xsl:otherwise> <xsl:value-of select="$rest"/> </xsl:otherwise> </xsl:choose> </xsl:variable> <xsl:variable name="newPath" select="concat($path, '/', $step)"/> <xsl:choose> <xsl:when test="contains($rest, '/')"> <dir name="{$step}"> <xsl:apply-templates select="$files[path = $newPath]"> <!--xsl:sort select="file/path"/--> </xsl:apply-templates> <xsl:call-template name="transformDocument"> <xsl:with-param name="path" select="$newPath"/> <xsl:with-param name="files" select="$files[starts-with(path, $newPath) and path != $newPath]"/> </xsl:call-template> </dir> </xsl:when> <xsl:otherwise> <!--only one token left--> <xsl:variable name="token" select="$step"/> <xsl:variable name="prev-token"> <xsl:call-template name="get-filename"> <xsl:with-param name="path" select="$path"/> </xsl:call-template> </xsl:variable> <xsl:choose> <xsl:when test="contains($token, 'html')"> <document targetdoc="{$prev-token}" baseuri="{$token}"> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="{$prev-token}.olinkdb.xml"/> </document> </xsl:when> <xsl:when test="contains($token, 'pdf')"> <xsl:variable name="basename" select="substring-before($token,'.pdf')"/> <document targetdoc="{$basename}" baseuri="{$token}"> <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" href="{$basename}.olinkdb.xml"/> </document> </xsl:when> <xsl:otherwise> <xsl:message>Problem with :(<xsl:value-of select="$token"/>) </xsl:message> </xsl:otherwise> </xsl:choose> </xsl:otherwise> </xsl:choose> <xsl:call-template name="transformDocument"> <xsl:with-param name="path" select="$path"/> <xsl:with-param name="files" select="$files[not(starts-with(path, $newPath))]"/> </xsl:call-template> </xsl:if> </xsl:template> <!-- The next template matches the <files> element and starts off the processing. I've assumed that there's only one root here. --> <xsl:template match="files"> <xsl:comment> THIS IS A GENERATED FILE DO NOT EDIT </xsl:comment> <targetset> <targetsetinfo> Description of this target database document, which is for the examples in olink doc. </targetsetinfo> <sitemap> <xsl:variable name="root" select="substring-before(file[1]/path, '/')"/> <dir name="{$root}"> <xsl:call-template name="transformDocument"> <xsl:with-param name="path" select="$root"/> <xsl:with-param name="files" select="file"/> </xsl:call-template> </dir> </sitemap> </targetset> </xsl:template> </xsl:stylesheet>
<?xml version="1.0" encoding="UTF-8"?> <files> <file> <path>share/doc/Corporate/Training/BuildQtApplicationsWithCMake.pdf</path> </file> <file> <path>share/doc/Corporate/Training/BuildQtApplicationsWithCMake/index.html</path> </file> <file> <path>share/doc/Corporate/Training/C++Handbook.pdf</path> </file> <file> <path>share/doc/Corporate/Training/C++Handbook/index.html</path> </file> <file> <path>share/doc/Corporate/Training/CodingStyle.pdf</path> </file> <file> <path>share/doc/Corporate/Training/CodingStyle/index.html</path> </file> <file> <path>share/doc/Corporate/Training/DebianHandbook.pdf</path> </file> <file> <path>share/doc/Corporate/Training/DebianHandbook/index.html</path> </file> <file> <path>share/doc/Corporate/Training/VirtualBox.pdf</path> </file> <file> <path>share/doc/Corporate/Training/VirtualBox/index.html</path> </file> <file> <path>share/doc/Corporate/Training/WritingDocumentationInDocbook.pdf</path> </file> <file> <path>share/doc/Corporate/Training/WritingDocumentationInDocbook/index.html</path> </file> </files>
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]