Last active
December 18, 2015 10:59
-
-
Save capncodewash/5772777 to your computer and use it in GitHub Desktop.
A simple XSLT 2.0 stylesheet which allows you to split a DocBook 5.1 assembly file containing multiple <structure> elements into distinct files for further processing. The end result is a set of files named after the IDs of each <structure> element. Each file contains:
* The entire <resources> structure from the original file
* A single <structu…
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
assembly-split.xsl | |
== README == | |
A simple XSLT 2.0 stylesheet which allows you to split a DocBook 5.1 assembly file containing multiple <structure> elements into distinct files for further processing. | |
The end result is a set of files named after the IDs of each <structure> element. Each file contains: | |
* The entire <resources> structure from the original file | |
* A single <structure> element | |
Example usage: | |
saxon -ext:on -xsltversion:2.0 my-assembly.xml assembly-split.xsl | |
== LICENCE == | |
The MIT License (MIT) | |
Copyright (c) 2013 Graeme West | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: | |
The above copyright notice and this permission notice shall be included in | |
all copies or substantial portions of the Software. | |
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | |
THE SOFTWARE. | |
--> | |
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:xs="http://www.w3.org/2001/XMLSchema" | |
xpath-default-namespace="http://docbook.org/ns/docbook" xmlns="http://docbook.org/ns/docbook"> | |
<xsl:template match="@*|node()"> | |
<xsl:copy> | |
<xsl:apply-templates select="@*|node()"/> | |
</xsl:copy> | |
</xsl:template> | |
<xsl:template match="/assembly"> | |
<xsl:for-each select="/assembly/structure"> | |
<xsl:result-document href="{@xml:id}.xml"> | |
<assembly> | |
<xsl:copy-of select="/assembly/resources" /> | |
<structure> | |
<xsl:apply-templates/> | |
</structure> | |
</assembly> | |
</xsl:result-document> | |
</xsl:for-each> | |
</xsl:template> | |
</xsl:stylesheet> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment