[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Confusing namespaces and xslt
I like to be as surgical as possible in my incremental transforms,
especially when I've got a lot of things to update. In this case, I
might use different modes, such as "content" and "append", as shown below:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:client="http://somecompany.com/box/client" xmlns:box="http://somecompany.com/box" exclude-result-prefixes="client"> <!-- BUSINESS LOGIC: --> <!-- Set the value for all <box:rotation-time> elements --> <xsl:template mode="content" match="box:rotation-time">newvalue</xsl:template> <!-- Append a <box:work-manager> element to the end of <work-managers> content --> <xsl:template mode="append" match="client:work-managers"> <box:work-manager> <!-- etc. --> </box:work-manager> </xsl:template> <!-- GENERIC UTILITY CODE: --> <!-- Identity transform for attributes, elements, comments, text, and PIs --> <xsl:template match="@* | node()"> <xsl:copy> <!-- Everything here (inside <xsl:copy>) only applies to elements --> <xsl:apply-templates select="@*"/> <xsl:apply-templates mode="content" select="."/> <xsl:apply-templates mode="append" select="."/> </xsl:copy> </xsl:template> <!-- By default, just process the existing content --> <xsl:template mode="content" match="*"> <xsl:apply-templates/> </xsl:template> <!-- By default, don't append anything --> <xsl:template mode="append" match="*"/> </xsl:stylesheet> In other cases, I've also used "insert" (insert before existing content), "before" (insert before the element itself), "after" (insert after the element), and "att-value" (for updating just the attribute value, without having to explicitly create a new attribute using <xsl:attribute> every time). Having such surgical precision can be very satisfying, but I don't usually bother if there are only one or two things to update (as in this example). But I thought I'd throw the idea out there anyway, in case you have lots of things to update or you anticipate adding more update rules. Evan Wendell Piez wrote: Paul,
|
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
|