[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: attribute value replacement and good book recomme

Subject: Re: attribute value replacement and good book recommendation.
From: chun ji <cji_work@xxxxxxxxx>
Date: Mon, 10 Sep 2007 14:23:45 -0700 (PDT)
Re:  attribute value replacement and good book  recomme
Hi Abel, 
thank you for the help, but I still can not make the
conversion working correctly, Here is my latest xsl
file I used: 
"
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:param name="user"/>
    <xsl:param name="pwd"/>

    <xsl:template match="node() | @*">
        <xsl:copy>
             <xsl:apply-templates select="node() | @*"
/>
        </xsl:copy>
    </xsl:template>

    <xsl:template
match="beans/bean/property/@username">
        <xsl:attribute name="username">
             <xsl:value-of select="$user" />
        </xsl:attribute>
    </xsl:template>

    <xsl:template
match="beans/bean/property/@password">
         <xsl:attribute name="password">
              <xsl:value-of select="$pwd" />
         </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>
"
But the output file is the same as my input xml file,
any comments ? 


Charlie, 



--- Abel Braaksma <abel.online@xxxxxxxxx> wrote:

> Hi Charlie,
> 
> I see you've been away from this list since end
> 2006, welcome back ;)
> 
> Changing attributes is as easy as 1-2-3 in XSLT, if
> you know how, that 
> is. You asked for a book as well. This template is
> explained in just 
> about any book on XSLT: in the "XSLT Cookbook" 1st
> edition and 2nd 
> edition (chapter 8); in Jeni Tennison's introductory
> book on XSLT; in 
> XSLT 2.0 Programmer's Reference (Michael Kay), under
> "xsl:copy"; in 
> "XSLT and XPath: A guide to XML Transformations" in
> chapter 9.2 (but not 
> well enough explained imho) etc etc. All these books
> are, as far as I 
> know, still available. I personally favor the
> Cookbook 2nd ed for 
> starters if you are good in working with examples,
> or Jeni Tennison's 
> "Beginning XSLT" (for xslt 1.0) or "Beginning XSLT
> 2.0" (for xslt 2.0) 
> if you like to get a good explanation and step by
> step of the language.
> 
> This is what they all explain:
> 
> <xsl:template match="node() | @*">
> <xsl:copy>
> <xsl:apply-templates select="node() | @*" />
> </xsl:copy>
> </xsl:template>
> 
> or some variant on that theme. It will copy the
> input XML to the output 
> without change. Next, all you have to do is add
> templates for the thing 
> you do want to change. For instance, in your case,
> @username and 
> @password when they are children of 'property'. Just
> add the following 
> to your stylesheet alongside the copy idiom:
> 
> <xsl:template match="property/@username">
> <xsl:attribute name="username">
> <xsl:value-of select="$user" />
> </xsl:attribute>
> </xsl:template>
> 
> <xsl:template match="property/@password">
> <xsl:attribute name="password">
> <xsl:value-of select="$pwd" />
> </xsl:attribute>
> </xsl:template>
> 
> 
> Of course, don't forget to include the parameters in
> your stylesheet 
> with the names you used in your ANT build script.
> I.e., use the 
> following top level declarations:
> 
> <xsl:param name="pwd" />
> <xsl:param name="user" />
> 
> 
> That's all there is to it. Really. Happy coding!
> 
> Cheers,
> -- Abel Braaksma
> 
> 
> PS: a start about XSLT: 
>
http://developer.mozilla.org/en/docs/Transforming_XML_with_XSLT
> (see 
> section on Further reading, it is a bit out of date,
> but gives you a 
> good starting point).
> 
> 
> chun ji wrote:
> > Hi there, 
> > I have couple of questions here. 
> >
> > Q1.
> > I want to replace some attribute values in a xml
> file,
> > but I am kind  new to the XSLT and is blocked for
> what
> > I should do next. 
> >
> > So here is my original xml file, old.xml?  
> >
> > ?
> > <?xml version="1.0" encoding="UTF-8"?>
> > <beans
> > xmlns=http://www.springframework.org/schema/beans
> ?>
> >
> >     <bean id="wandDataSource" class="?#34;
> > destroy-method="close" scope="singleton">
> >         <property name="driverClassName"
> > value="oracle.jdbc.driver.OracleDriver"/>
> >         <property name="url"
> >
> value="jdbc:oracle:thin:@www.boogle.com:1521:abcd"/>
> >         <property name="username"
> > value="someusername"/>
> >         <property name="password"
> > value="somepassword"/>
> >     </bean>
> >     
> > </beans>
> > ?
> >
> > I want to replace the username & password with the
> > value I give, for example, newuser?&
> newpassword?
> > But that old.xml?file is randomly generated, and
> I
> > dont know the value of username?and password?>
in
> > it, when these are being replaced. So in that
> case,
> > what this xsl template file should be looks like? 
> >
> > Here is the target in my ANT script, that I used
> to
> > try to make that replacement. 
> > ??> >    <target name="updateXML">
> >       <xslt in="old.xml" out="new.xml"
> > style="update.xsl">
> >          <param name=user" expression=newuser"/>
> >          <param name="pwd" expression="newpassword
> "/>
> >      </xslt>
> >    </target>
> >   ?> > ?> >
> > Q2. 
> > I started to learn this kind of XML/XSLT tool
> almost 9
> > months ago, , but I still feel that there are lots
> of
> > things that I dont know.  Does someone know if
> there
> > are some good XML books in the market? Or some
> website
> > that can give a beginner very decent XML
> education?  I
> > think that would help me a lot. 
> >
> >
> > Thanks in advance.
> >
> >
> > Charlie. 
> >
> >
> >
> >        
> >
>
____________________________________________________________________________________
> > Pinpoint customers who are looking for what you
> sell. 
> > http://searchmarketing.yahoo.com/
> 
> 



      ____________________________________________________________________________________
Don't let your dream ride pass you by. Make it a reality with Yahoo! Autos.
http://autos.yahoo.com/index.html

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.