[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: attribute value replacement and good book recomme
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.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|