Post by The NFL Edge on Dec 22, 2010 14:57:27 GMT -5
While this has very little relevance to sports handicapping I am so proud of my latest invention... I just had to tell someone!!
So here we have my latest invention, an XSLT (2.0) Stylesheet that breaks a large file up into smaller files and the best part is that it renames the resulting files by the name designated in the title element of that component. F**ING AMAZING.
It has taken me a couple of days of playing around to come up with it, and I am really pleased with how it works. Here is the code, please note it assumes you are working with valid Docbook XML files. Feel free to use this, as long as you give credit to Panageotech, and maybe even post a thank you or something.
Note replace the match= variable with the element name that you want it to split on.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<!-- ********************************************************************
A style sheet to split out main doc into several sect2 docs
********************************************************************
DEVELOPED BY PANAGEOTECH 2010
********************************************************************
Note the DOCBOOK output Declaration
********************************************************************
Copyright Panageotech 2010
******************************************************************** -->
<!-- G-Splitter04: Splits Large File into Smaller files based on the match=element -->
<!-- The Beauty of this it RENAMES the output filebased on the match/title elem= -->
<!-- ==================================================================== -->
<xsl:output method="xml" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN"
doctype-system="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
indent="yes" omit-xml-declaration="no"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sect2">
<xsl:variable name="filename">
<xsl:value-of select="title"/>
</xsl:variable>
<xi:include href="{$filename}.xml"
xmlns:xi="http://www.w3.org/2001/XInclude"/>
<xsl:result-document href="{$filename}.xml">
<xsl:next-match/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>
So here we have my latest invention, an XSLT (2.0) Stylesheet that breaks a large file up into smaller files and the best part is that it renames the resulting files by the name designated in the title element of that component. F**ING AMAZING.
It has taken me a couple of days of playing around to come up with it, and I am really pleased with how it works. Here is the code, please note it assumes you are working with valid Docbook XML files. Feel free to use this, as long as you give credit to Panageotech, and maybe even post a thank you or something.
Note replace the match= variable with the element name that you want it to split on.
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0">
<!-- ********************************************************************
A style sheet to split out main doc into several sect2 docs
********************************************************************
DEVELOPED BY PANAGEOTECH 2010
********************************************************************
Note the DOCBOOK output Declaration
********************************************************************
Copyright Panageotech 2010
******************************************************************** -->
<!-- G-Splitter04: Splits Large File into Smaller files based on the match=element -->
<!-- The Beauty of this it RENAMES the output filebased on the match/title elem= -->
<!-- ==================================================================== -->
<xsl:output method="xml" doctype-public="-//OASIS//DTD DocBook XML V4.1.2//EN"
doctype-system="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"
indent="yes" omit-xml-declaration="no"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="sect2">
<xsl:variable name="filename">
<xsl:value-of select="title"/>
</xsl:variable>
<xi:include href="{$filename}.xml"
xmlns:xi="http://www.w3.org/2001/XInclude"/>
<xsl:result-document href="{$filename}.xml">
<xsl:next-match/>
</xsl:result-document>
</xsl:template>
</xsl:stylesheet>