Announcement Announcement Module
Collapse
No announcement yet.
Using XSLT on a xsd-based spring-beans xml file Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using XSLT on a xsd-based spring-beans xml file

    ant version 1.8.1
    spring version 3.0.5

    I have a spring beans file, defined using the schema spring-beans.xsd
    This file used to be defined using the spring-beans.dtd.

    I changed the spring beans file to use the spring-beans.xsd instead.
    The xslt transformation does not work any longer.
    It appears that it cannot take as input a spring-beans file and treat it as a simple xml file.
    It does not recognize
    <xsl:template match="/beans">
    or once passed the root beans
    <xsl:template match="bean">

    I changed the first match to
    <xsl:template match="/">
    so at least I got past this point but then it does not recognize the children "bean".

    -----

    This is the ant target xslt task:
    <xslt style="${xslts.dir}/apimappingDefs2Java.xsl"
    in="@{api.file}"
    out="${gen-src.dir}/com/navis/${app.name}/${app-cap.name}${FILENAME_BASE}.java"
    filenameparameter="fileName">
    <param name="className" expression="${app-cap.name}${FILENAME_BASE}"/>
    <param name="packageName" expression="com.navis.${app.name}"/>
    </xslt>

    ---------

    This is the xslt file:

    <?xml version="1.0" encoding="UTF-8" ?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:import href="utils.xsl"/>
    <xsl:output indent="no" method="text" omit-xml-declaration="yes"/>
    <xslaram name="packageName">com.navis.framework</xslaram>
    <xslaram name="className">ApiMappings</xslaram>
    <xsl:template match="/"><xsl:text>/*
    * Copyright (c) 2005-2011 Navis LLC. All Rights Reserved.
    *
    */
    package </xsl:text>
    <xsl:value-of select="$packageName"/><xsl:text>;

    /**
    *
    * Api Mapping ID constants (primarily to be used by JUnit testing classes).
    *
    */
    public class </xsl:text>
    <xsl:value-of select="$className"/>
    <xsl:text> {
    private </xsl:text>
    <xsl:value-of select="$className"/>
    <xsl:text>() {} // for Josh Bloch</xsl:text>
    <xsl:call-template name="NewLine"/>

    <xsl:apply-templates select="bean"/>
    <xsl:call-template name="NewLine"/>
    <xsl:text>}</xsl:text>
    <xsl:call-template name="NewLine"/>
    </xsl:template>

    <!-- e.g. public static final String FOO = "FOO"; -->
    <xsl:template match="bean">
    <xsl:text> public static final String </xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text> = "</xsl:text>
    <xsl:value-of select="@id"/>
    <xsl:text>";</xsl:text>

    <xsl:call-template name="NewLine"/>
    </xsl:template>

    </xsl:stylesheet>

    ---------------------------------------------------------

    The header part of my spring beans file is:

    <?xml version="1.0" encoding="UTF-8"?>

    <beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"
    >

    --------------------------------------------------------

    Do I need to do something, maybe pass some parameters to the ant xslt target so that the input file (spring beans file) is parsed like a plain XML file?
    Last edited by gisellas; May 11th, 2011, 01:42 PM.

  • #2
    I am answering my own question.

    I had to add the namespace to the .xslt file, so it would be:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
    xmlns:sb="http://www.springframework.org/schema/beans">

    ---

    Then in the body of the xslt, I would use the namespace abbreviation, e.g.,
    <xsl:template match="/sb:beans">
    for any spring bean elements.

    ---------------
    Problem has been solved.

    Comment

    Working...
    X