Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 1st, 2005, 01:02 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default xml and xsl templates as input to xslt gives xml

Hi All,
      Since i'm new to xslt i have some doubts in that.

My problem is to generate build.xml using xml and xml or xsl templates with the help of xslt.

For example i have one input.xml which contains input data to output xml and need to create a template either using xml or xsl.

Now i need to give both input.xml and templates as input to xslt
and generate the complete xml file that should be stored in the
specified directory.


i also do not know how to create template please help me in this regard.

the following are my xml files:

************************************************** *****

<project name="module-name" default="all" basedir=".">

  <description>
    Basic template that could be used as a build file by individual module owners.
  </description>




  <property name="module-name" value="from iput.xml some module name comes here"/>
  <property name="module-dst" value="from input.xml fetch path value to the same module comes here"/>
  <property name="rmic-class-name" value=" similarly here also some values here"/>
  <property name="interface-class-name" value=" silmilarly here alsosome values here"/>



  <target name="clean">
    <delete>
      <fileset dir="${module-dst}" />
    </delete>
    <echo message="Removed directory ${module-dst}"/>
  </target>

  <target name="compile" description="Compiling individual modules">
   <rmic includes="${rmic-class-name}" base="${DST}" />
    <jar destfile="${CLIENTJAR}" update="true">
      <fileset dir=".">
        <include name="*_Stub.class"/>
      </fileset>
      <fileset dir=".">
        <include name="${interface-class-name}"/>
      </fileset>
    </jar>
  </target>

  <target name="all" depends="compile"/>

</project>

************************************************** ***********
 in the above xml i need to modify some properties only and remaining
are same since it is ANT build file that has to be modified according to the specified module .i want to generate build.xml file
using xslt and put them in the particular place.


its very urgent for me please help me.




*************************************************
this is input.xml

<?xml version="2.0"?>
<subbuild>
   <module>
             <parameter module-name="communicator">
             <parameter module-path="com\ram\nms\${module-name}">
             <parameter rmic-classname="${module-path}\server\cache.class"> </module>
</subbuild>

***********************************


output.xml


build.xml with filled values.




Thanks and Regards


 
Old August 1st, 2005, 03:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You say the problem is urgent: one thing I always advise people is that you shouldn't try to learn a new technology when you have deadlines. If the problem is urgent, tackle it using a technology you are already familiar with.

I'm a little confused by your requirement: I think you are using "template" with a general English meaning, not with its particular XSLT meaning, is that right? Similarly, your "path" is a filestore path, not an XPath path expression?

I think this transformation is basically an identity transformation:

<xsl:template match="*">
  <xsl:copy>
  <xsl:copy-of select="@*"/>
  <xsl:apply-templates/>
  </xsl:copy>
</xsl:template>

supplemented by special code for the <property> element:

<xsl:template match="property">
<property>
  <xsl:copy-of select="@name"/>
  <xsl:attribute name="value">
    <xsl:apply-templates select="@value"/>
  </xsl:attribute>
</property>
</xsl:template>

<xsl:template match="property[@name='module-name']/@value">
  <xsl:value-of select="document('input.xml')/subbuild/module/parameter/@module-name"/>
</xsl:template>

<xsl:template match="property[@name='module-dst']/@value">
  <xsl:value-of select="document('input.xml')/subbuild/module/parameter/@module-path"/>
</xsl:template>

etc.





Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 1st, 2005, 05:31 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael Kay,
              Thanks for your information.
But still i have some doubts like

How to create resultant xml using xml and xsl.
I want to store the resultant xml file in the specified directory how to do same.



I think you might have understood my requirement


I have a build.xml file in that i need to modify some property values according to the respective module and all remaining are same.
To avoid repeatation I need to create a template because that can be reused and create a seperate build.xml for each module.

please explain me in detail because i 'm new to this xslt.
but its very urgent.
i know how to do this using java but the requirement is in xslt.


Thanks and Regards



 
Old August 1st, 2005, 06:07 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

>How to create resultant xml using xml and xsl.
>I want to store the resultant xml file in the specified directory how to do same.

Every XSLT transformation takes an XML file as input, applies an XSLT stylesheet, and produces an XML (or sometimes HTML or text) file as output, so this question is pretty basic. The details of how to run it depend on the processor you are using. With Saxon, for example, running it from the command line, you would do:

java net.sf.saxon.Transform -o result.xml source.xml stylesheet.xsl

There's also a Java API allowing you to invoke transformations from your application.

I'm sorry, but telling me that it's urgent makes me feel it might have been a mistake to answer your question. You should either allow enough time in your schedule to learn this technology properly, or you should use a technology that you already understand.




Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old August 3rd, 2005, 01:55 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Michael Kay,
                Thanks for your information. Its working nicely but I need some more information like I need to add parameters for various modules in input.xml and then hoe to read all data from that file.

input.xml

<?xml version="2.0"?>
<subbuild>
   <module name="comunicator">
             <parameter module-name="communicator">
             <parameter module-path="com\ram\nms\${module-name}">
             <parameter rmic-classname="${module-path}\server\cache.class"> </module>
<module name="some module name comes here">
             <parameter module-name="some values">
             <parameter module-path="some values">
             <parameter rmic-classname="some values">
</module
</subbuild>


 
Old August 3rd, 2005, 01:58 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it has to read one module at a time depends on the module name that we give


Thanks and Regards






Similar Threads
Thread Thread Starter Forum Replies Last Post
Multiple input xml / get data from other xml file elayaraja.s XSLT 3 July 25th, 2008 06:59 AM
Converting Source Xml into Target Xml Using XSL. alapati.sasi XSLT 3 May 14th, 2007 10:54 AM
XSLT transformation from XML buffer and XSL file sundaramkumar Javascript 1 September 5th, 2005 02:11 AM
xsl:apply-templates on Variable containing xml nexus5 XSLT 9 November 4th, 2004 02:55 PM
merge two xml file and make new xml using xslt ketan XSLT 0 September 21st, 2004 08:48 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.