Announcement Announcement Module
Collapse
No announcement yet.
XSL for converting old beans xml to new short format Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    Thanks. We should perhaps put this on springframework.org somewhere.

    Comment

    Working...
    X