Results 1 to 2 of 2

Thread: XSL for converting old beans xml to new short format

  1. #1
    Join Date
    Jul 2005
    Location
    Helsinki, Finland
    Posts
    12

    Default XSL for converting old beans xml to new short format

    You can use this XSL to convert from old beans xml to new short format.

    Save this as "transformbeans.xsl" .

    usage:

    xsltproc transformbeans.xsl applicationContext.xml > applicationContext.xml.new

    or

    java -jar xalan.jar -XSL transformbeans.xsl -IN applicationContext.xml -OUT applicationContext.xml.new


    - Lari



    Here's "transformbeans.xsl":

    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!-- Transforms old Spring XML beans configuration to new short format -->
    <!-- Author&#58; Lari Hotari, Sagire Software Oy, 30.7.2005 -->
    <xsl&#58;stylesheet xmlns&#58;xsl="http&#58;//www.w3.org/1999/XSL/Transform"
    		version="1.0">
    	<xsl&#58;output method="xml" indent="yes" encoding="ISO-8859-1" doctype-public="-//SPRING//DTD BEAN//EN" doctype-system="http&#58;//www.springframework.org/dtd/spring-beans.dtd" />
    	<xsl&#58;strip-space elements="*"/>
    	
    	<xsl&#58;template match="bean">
    		<xsl&#58;copy>
    			<xsl&#58;apply-templates select="@id"/>
    			<xsl&#58;apply-templates select="@name"/>
    			<xsl&#58;apply-templates select="@class"/>
    			<xsl&#58;apply-templates select="@parent"/>
    			<xsl&#58;if test="@abstract!='false'">
    				<xsl&#58;apply-templates select="@abstract"/>
    			</xsl&#58;if>
    			<xsl&#58;if test="@singleton!='true'">
    				<xsl&#58;apply-templates select="@singleton"/>
    			</xsl&#58;if>
    			<xsl&#58;if test="@lazy-init!='default'">
    				<xsl&#58;apply-templates select="@lazy-init"/>
    			</xsl&#58;if>
    			<xsl&#58;if test="@autowire!='default'">
    				<xsl&#58;apply-templates select="@autowire"/>
    			</xsl&#58;if>
    			<xsl&#58;if test="@dependency-check!='default'">
    				<xsl&#58;apply-templates select="@dependency-check"/>
    			</xsl&#58;if>
    			<xsl&#58;apply-templates select="@depends-on"/>
    			<xsl&#58;apply-templates select="@init-method"/>
    			<xsl&#58;apply-templates select="@destroy-method"/>
    			<xsl&#58;apply-templates select="@factory-method"/>
    			<xsl&#58;apply-templates select="@factory-bean"/>
    			<xsl&#58;apply-templates select="node&#40;&#41;"/>
    		</xsl&#58;copy>
    	</xsl&#58;template>
    	
    	<xsl&#58;template match="entry">
    		<xsl&#58;copy>
    			<xsl&#58;apply-templates select="@*"/>
    			<xsl&#58;if test="count&#40;ref&#41; > 0">
    				<xsl&#58;attribute name="value-ref">
    					<xsl&#58;choose>
    						<xsl&#58;when test="string-length&#40;ref/@local&#41; > 0">
    							<xsl&#58;value-of select="ref/@local"/>
    						</xsl&#58;when>
    						<xsl&#58;otherwise>
    							<xsl&#58;value-of select="ref/@bean"/>
    						</xsl&#58;otherwise>
    					</xsl&#58;choose>
    				</xsl&#58;attribute>
    			</xsl&#58;if>
    			<xsl&#58;if test="count&#40;value&#41; > 0">
    				<xsl&#58;choose>
    					<xsl&#58;when test="string-length&#40;normalize-space&#40;value/text&#40;&#41;&#41;&#41;=0">
    						<xsl&#58;apply-templates select="value"/>
    					</xsl&#58;when>
    					<xsl&#58;otherwise>
    						<xsl&#58;attribute name="value">
    							<xsl&#58;value-of select="value/text&#40;&#41;"/>
    						</xsl&#58;attribute>
    					</xsl&#58;otherwise>
    				</xsl&#58;choose>
    			</xsl&#58;if>
    			<xsl&#58;apply-templates select="./node&#40;&#41;&#91;name&#40;&#41; != 'value' and name&#40;&#41; != 'ref'&#93;"/>
    		</xsl&#58;copy>
    	</xsl&#58;template>
    	
    	<xsl&#58;template match="property">
    		<xsl&#58;choose>
    			<xsl&#58;when test="count&#40;ref&#41; > 0">
    				<xsl&#58;copy>
    					<xsl&#58;apply-templates select="@*"/>
    					<xsl&#58;attribute name="ref">
    						<xsl&#58;choose>
    							<xsl&#58;when test="string-length&#40;ref/@local&#41; > 0">
    								<xsl&#58;value-of select="ref/@local"/>
    							</xsl&#58;when>
    							<xsl&#58;otherwise>
    								<xsl&#58;value-of select="ref/@bean"/>
    							</xsl&#58;otherwise>
    						</xsl&#58;choose>
    					</xsl&#58;attribute>
    				</xsl&#58;copy>
    			</xsl&#58;when>
    			<xsl&#58;when test="string-length&#40;normalize-space&#40;value/text&#40;&#41;&#41;&#41;=0">
    				<xsl&#58;copy>
    					<xsl&#58;apply-templates select="@*"/>
    					<xsl&#58;apply-templates select="node&#40;&#41;"/>
    				</xsl&#58;copy>
    			</xsl&#58;when>
    			<xsl&#58;otherwise>
    				<xsl&#58;copy>
    					<xsl&#58;apply-templates select="@*"/>
    					<xsl&#58;attribute name="value">
    						<xsl&#58;value-of select="value/text&#40;&#41;"/>
    					</xsl&#58;attribute>
    				</xsl&#58;copy>
    			</xsl&#58;otherwise>
    		</xsl&#58;choose>
    	</xsl&#58;template>
    	
    	<xsl&#58;template match="node&#40;&#41;">
    		<xsl&#58;copy>
    			<xsl&#58;apply-templates select="@*"/>
    			<xsl&#58;apply-templates select="node&#40;&#41;"/>
    		</xsl&#58;copy>
    	</xsl&#58;template>
    	
    	<xsl&#58;template match="@*">
    		<xsl&#58;copy />
    	</xsl&#58;template>
    </xsl&#58;stylesheet>
    [/code]

  2. #2
    Join Date
    Aug 2004
    Location
    San Mateo, CA
    Posts
    1,265

    Default

    Thanks. We should perhaps put this on springframework.org somewhere.
    Rod Johnson - GM, SpringSource Division, VMware
    http://www.springsource.com
    Spring From the Source

Similar Threads

  1. Spring container fails with no exception
    By naor in forum Container
    Replies: 9
    Last Post: Oct 1st, 2005, 03:39 PM
  2. Replies: 0
    Last Post: Aug 25th, 2005, 05:11 AM
  3. Replies: 4
    Last Post: Aug 17th, 2005, 04:42 AM
  4. Stack Overflow
    By rayho222 in forum Container
    Replies: 6
    Last Post: May 17th, 2005, 03:42 AM
  5. Help with integration of custom beans xml format
    By CameronBraid in forum Container
    Replies: 1
    Last Post: Aug 16th, 2004, 12:39 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •