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 4th, 2005, 01:37 AM
Authorized User
 
Join Date: Jul 2005
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default command line inputs for xsl

Hi,
   can anyone give me solution for the following :

I have build.xml ,trans.xsl and input.xml.

trans.xsl:

<?xml version ="1.0" encoding ="iso-8859-1" ?>

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

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



<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[@name='inventor']/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>

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


build.xml:


<?xml version="1.0" encoding="iso-8859-1"?>
<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="some value comes here from input.xml"/>
  <property name="module-dst" value="some value comes here from input.xml"/>
  <property name="rmic-class-name" value="some value comes here from input.xml"/>
  <property name="interface-class-name" value="some value comes here from input.xml"/>
  <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>


input.xml:



<?xml version="1.0" encoding="iso-8859-1"?>
<subbuild>
   <module name="communicator">
             <parameter module-name="communicator"/>
             <parameter module-path="com\ram\nms\${module-name}"/>
             <parameter rmic-class-name="${module-path}\server\cache.class"/>
             <parameter interface-class-name="rameshnarayan"/>
   </module>

</subbuild>



I'm running this from command line using saxon processor it is working nicely.

the problem is that i need to give more module information in the input.xml like


<?xml version="1.0" encoding="iso-8859-1"?>
<subbuild>
   <module name="communicator">
             <parameter module-name="communicator"/>
             <parameter module-path="com\ram\nms\${module-name}"/>
             <parameter rmic-class-name="${module-path}\server\cache.class"/>
             <parameter interface-class-name="rameshnarayan"/>
   </module>
   <module name="inventor">
             <parameter module-name="inventor"/>
             <parameter module-path="com\ram\nms\${module-name}"/>
             <parameter rmic-class-name="${module-path}\server\cache.class"/>
             <parameter interface-class-name="rameshnarayan"/>
   </module>

</subbuild>


My requirement is to read values of one particular module info at a time and generate the resultant.xml

I need to give the module name as parameter from the command line while running accordingly it has to process that particular module info from input.xml and produce resultant.xml.


Thanks and Regards

 
Old August 4th, 2005, 01:53 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Firstly, I would not retrieve the "input.xml" every time, store it in a variable. Although I suspect that Mr. Kay's programming skills are such that Saxon caches requests for external documents it seems good practice not to rely on it.

Secondly add an xsl:param element which you pass the name of the module. You can then use a second variable to filter the input.xml
Code:
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:param name="moduleName" />
<xsl:variable name="input" select="document('input.xml')" />
<xsl:variable name="module" select="$input/subbuild/module[@name = $moduleName]" />
Another improvement might be to also pass the name of the secondary file:
Code:
<xsl:param name="inputDoc"/>
<xsl:variable name="input" select="document($inputDoc)" />
You can then pass in the params at the command line:
Code:
java -jar saxon8.jar source.xml style.xsl moduleName=communicator [inputDoc=input.xml]

--

Joe (Microsoft MVP - XML)
 
Old August 4th, 2005, 04:38 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

You're almost there.

Add a global parameter to your stylesheet:

<xsl:param name="module"/>

In your templates, change the path expression to:

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

On the command line, add the parameter value:

java ... source.xml style.xsl module=inventor

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

Hi Joe and Michael Kay,


Thanks for your information finally i got my output.


cheers







Similar Threads
Thread Thread Starter Forum Replies Last Post
XQuery from command line Tomi XSLT 2 January 16th, 2008 01:58 PM
Asp Command Line dizzy1 Classic ASP Basics 1 August 30th, 2007 06:32 PM
passing command line parameters to xsl rameshnarayan XSLT 4 August 3rd, 2005 06:21 AM
command line switches pakman Excel VBA 3 June 9th, 2005 08:29 AM
Command line switches jaucourt Flash (all versions) 0 December 31st, 2004 07:29 AM





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