> -----Original Message-----
> From: [EMAIL PROTECTED] 
> [mailto:[EMAIL PROTECTED] On 
> Behalf Of Brian Agnew
> Sent: Friday, March 28, 2008 5:33 AM
> To: Karr, David
> Cc: xmltask-users@lists.sourceforge.net
> Subject: Re: [Xmltask-users] Add text to web-app/description 
> if it's present
> 
> Hi David -
> 
> 1) I think the problem is that Ant properties are 
> derived/expanded per task. That is, populating a property 
> within XMLTask makes it available for use in another task, 
> but not the current one. I'm not able to investigate further 
> at the moment, but copying into your property in one XMLTask 
> invocation then writing using another one appears to work. e.g.
> 
>       <xmltask source="web.xml">
>         <copy path="..." property="..."/>
>       <xmltask>
>       <xmltask source="web.xml" dest="web-out.xml">
>          <paste.../>
> 
> etc. appears to work for the below.

Acknowledged.  I had experimented with that, but I think I had something
else wrong at the time.  I'll try that again.

> 2) Can you clarify your 'last child' comment below ? <paste> 
> is a synonym for <insert> and does have some positional 
> control (under/before/after).
> But I'm not sure that's your problem.

I'm not sure what else I can clarify.  The xpath on my paste/insert is
"/*[local-name()='web-app']/.".  I'm trying to insert the "description"
element as the first child of "web-app", but it inserts it as the last
child.

Perhaps if I can change the xpath to refer to the first element child of
"web-app", and then use 'position="before"' on the paste, but my first
attempt at this:

        "/*[local-name()='web-app']/child::node()[1]/."

Resulted in an output file that was ONLY the xml directive, and nothing
else.

> 3) Can you clarify your 'trim' comment below ? Sounds like a 
> possible feature if I'm interpreting you correctly.

I'm trying to have the result be "<description>text</description>".  In
order to remove the extraneous newlines, I had to arrange it like this:

<replace if="existingDescription"
path="/*[local-name()='web-app']/*[local-name()='description']/text()"
                     expandProperties="true"
                ><![CDATA[${existingDescription} - ${label}:
${labelDesc}]]></replace>

Notice the ending ">" of the start tag next to the start of the CDATA,
and the end tag at the end of the line with the CDATA.

> 
> nb. your XPaths may be simplified by using
> 
> /:web-app/:description
> 
> rather than the verbose but correct 'local-name()' syntax 
> (caveat: not tried - just by inspection).

I'll try that.  I think some people had tried that in other contexts and
it didn't work.

> Hope that's of use. Please let me know how you get on...
> 
> Brian
> 
> On Thu, March 27, 2008 23:56, Karr, David wrote:
> > It's been a while since I've xmltasked.  I'm having some trouble 
> > getting done what I need.
> >
> > I have some text in a couple properties (I'm hardcoding the 
> values for
> > now) that I want to put into the "/web-app/description" 
> element of a 
> > web.xml file.  If the element is already present, I want to add the 
> > new text after " - ".  If the element wasn't present, then 
> create the 
> > element with the new text.
> >
> > I have two current problems:
> >
> > If the "description" element was present already, it's supposed to 
> > insert a value referencing the property containing the 
> existing value.
> > Instead of the value of the property, it just inserts 
> > "${existingDescription}".  I tried printing out the property value 
> > after the xmltask tag, and it appears to be fine.
> >
> > If the "description" element was NOT present, I insert the new 
> > "description" element (using that weird trick just talked about for 
> > turning off insertion of empty "xmlns" attributes), but it 
> inserts it 
> > as the last child of "web-app", not the first.  I don't see 
> a way to 
> > do this cleanly.
> >
> > I also wish there was a cleaner way to "trim" the resulting output 
> > (see what I had to do in the first "replace").
> >
> > Here's my current code:
> > ---------------------
> > <target name="install-label-info">
> >         <taskdef name="xmltask"
> > classname="com.oopsconsultancy.xmltask.ant.XmlTask"
> >                  classpath="${file.reference.xmltask.jar}"/>
> >         <property name="label" value="abc"/>
> >         <property name="labelDesc" value="def"/>
> >         <xmltask source="${build.web.dir}/WEB-INF/web.xml"
> > dest="${build.web.dir}/WEB-INF/web.xml" report="true">
> >                     <copy
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> > property="existingDescription"/>
> >             <replace if="existingDescription"
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> >                      expandProperties="true"
> >                 ><![CDATA[${existingDescription} - ${label}:
> > ${labelDesc}]]></replace>
> >             <paste unless="existingDescription"
> > path="/*[local-name()='web-app']/.">
> >                 <![CDATA[<description
> > xmlns="http://java.sun.com/xml/ns/j2ee";>${label}:
> > ${labelDesc}</description>]]>
> >             </paste>
> >                     <copy
> > 
> path="/*[local-name()='web-app']/*[local-name()='description']/text()"
> > property="newDescription"/>
> >         </xmltask>
> >         <echo 
> message="existingDescription[${existingDescription}]"/>
> >         <echo message="newDescription[${newDescription}]"/>
> >     </target>
> > ---------------------
> >
> >
> >
> >
> > 
> ----------------------------------------------------------------------
> > --- Check out the new SourceForge.net Marketplace.
> > It's the best place to buy or sell services for just about anything 
> > Open Source.
> > 
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marke
> > tplace _______________________________________________
> > Xmltask-users mailing list
> > Xmltask-users@lists.sourceforge.net
> > https://lists.sourceforge.net/lists/listinfo/xmltask-users
> >
> 
> 
> -- 
> Brian Agnew                  http://www.oopsconsultancy.com
> OOPS Consultancy Ltd
> Tel: +44 (0)7720 397526
> Fax: +44 (0)20 8682 0012
> 
> 
> --------------------------------------------------------------
> -----------
> Check out the new SourceForge.net Marketplace.
> It's the best place to buy or sell services for just about 
> anything Open Source.
> http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.n
et/marketplace
> _______________________________________________
> Xmltask-users mailing list
> Xmltask-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/xmltask-users
> 

-------------------------------------------------------------------------
Check out the new SourceForge.net Marketplace.
It's the best place to buy or sell services for
just about anything Open Source.
http://ad.doubleclick.net/clk;164216239;13503038;w?http://sf.net/marketplace
_______________________________________________
Xmltask-users mailing list
Xmltask-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/xmltask-users

Reply via email to