[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: default attribute values?
Peter,
At 12:11 PM 8/2/2002, you wrote: > In fact if you used templates instead of the copy-of, you could generalize > this for all the attributes: > > <input name="default" name2="default2"> > <xsl:apply-templates select="@*"/> > </input> > > <xsl:template match="node/@*"> > <xsl:copy-of select="."/> > </xsl:template> > > <xsl:template match="@gunk" priority="1"> > <xsl:attribute name="name"> > <xsl:value-of select="."/> > </xsl:attribute> > </xsl:template> > > Note that on the template for the attribute whose name is changing (@gunk > to @name), an explicit priority is necessary to make sure that template > fires instead of the template that copies. Quite so. Remember the original context was one of copying attribute values, only giving them defaults if they weren't provided, and then the poster asked what if he wanted to change an attribute's name as well.... I was merely extending the logic you had already provided to do the simpler job with xsl:copy-of -- despite the inference one might draw that here the technique had to be abandoned for a choose. :-> As for efficiency, you are quite right, the xsl:choose may be faster ... yet I have learned to hesitate to second-guess what one or another smart compiler might do -- any difference will surely be significant only on very large documents or very dumb processors (or we'd be recommending xsl:choose over match-based template selection all the time, no?). As for clarity, again you're right, xsl:choose is often clearer especially to the newcomer -- which is all the more reason to expose the "purer" template-driven approach when we can, since it is after all more versatile (and easier to maintain once you understand it), isn't it? In trolling through all the old threads I came across the interesting observation that newbies' code (viz.: lots of xsl:for-each and xsl:choose) often looks horrible to the experienced XSLTer, while our code may just look obscure to the newbie. This is largely due to the slow ramp-up to the powerful template-driven patterns that we eventually get more practice with. All the more reason to expose the alternatives, and discuss the differences, from time to time.... Cheers, Wendell
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
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
|