[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Batch transformations

Subject: Batch transformations
From: Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx>
Date: Sat, 22 Mar 2008 09:37:08 +0000
 Batch transformations
>>>>> "Colin" == Colin Paul Adams <colin@xxxxxxxxxxxxxxxxxx> writes:

    Aaron> To allow groups of files to be translated.

    Colin> But this can be done within a transformation using
    Colin> collection and xsl:result-document.

To illustrate. The following transformation, if invoked as:

gestalt --template=initial batch.xsl

does the following:

For every file in the current working directory that contains the
characters .xsl as part of its filename, it writes another files with
the name changed to end in .out. 
The contents of each such file is the single element document,
containing a text node of the document URi of the original file.

But any other transformation can be coded just by changing the
contents of the xsl:result-document element.

<?xml version="1.0" encoding="utf-8"?>
<xsl:transform 
   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
   xmlns:xs="http://www.w3.org/2001/XMLSchema"
   xmlns:gexslt="http://www.gobosoft.com/eiffel/gobo/gexslt/extension"
   exclude-result-prefixes="gexslt xs"
   version="2.0">

<xsl:output method="xml" indent="yes"/>

<xsl:template name="initial">
 <xsl:variable name="col" as="node()*">
  <xsl:sequence select="collection()"/>
 </xsl:variable>
 <doc>
  <xsl:choose>
   <xsl:when test="system-property ('gexslt:standard-file-collection') eq 'yes'">
    <xsl:for-each select="$col">
     <xsl:choose>
       <xsl:when test="gexslt:file/@xml:base[contains(.,'.xsl')]">
	 <xsl:apply-templates mode="batch" select="doc(.)"/>
       </xsl:when>
     </xsl:choose>
    </xsl:for-each>
   </xsl:when>
   <xsl:otherwise>
    <xsl:value-of>Standard file: collection is not available</xsl:value-of>
   </xsl:otherwise>
  </xsl:choose>
 </doc>
</xsl:template>

<xsl:template mode="batch" match="/">
  <xsl:variable name="doc-uri" select="document-uri(.)" as="xs:string"/>
  <xsl:variable name="out" select="concat(substring-before($doc-uri, 'xsl'), 'out')" as="xs:string"/>
  <xsl:result-document href="{$out}">
    <document>
      <xsl:value-of select="$doc-uri"/>
    </document>
  </xsl:result-document>
</xsl:template>

</xsl:transform>

-- 
Colin Adams
Preston Lancashire

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.