[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Identity and Modified identity transforms
On 03/12/2007, Michael Kay <mike@xxxxxxxxxxxx> wrote: > > I don't know of the top of my head what node()[1] would do if > > the currrent node was an attribute... > > Attributes don't have children, so child::node()[1] returns an empty > sequence. It seems: <xsl:template match="@*|node()"> <xsl:copy> <xsl:apply-templates select="@*|node()[1]"/> </xsl:copy> <xsl:apply-templates select="following-sibling::node()[1]"/> </xsl:template> ...is fine because xsl:copy copies the entire attribute (name and value). From: http://www.w3.org/TR/xslt20/#element-copy "When the context item is an attribute node, text node, comment node, processing instruction node, or namespace node, the xsl:copy instruction returns a new node that is a copy of the context node. The new node will have the same node kind, name, and string value as the context node. In the case of an attribute node, it will also have the same values for the is-id and is-idrefs properties. The sequence constructor, if present, is not evaluated." So the two apply-templates instructions are redundant when the context node is an attribute, making the above template compact but perhaps inefficient. The extra template in the two-template version could be shortened ever so slightly to: <xsl:template match="node()"> <xsl:copy> <xsl:apply-templates select="@*|node()[1]"/> </xsl:copy> <xsl:apply-templates select="following-sibling::node()[1]"/> </xsl:template> <xsl:template match="@*"> <xsl:copy/> </xsl:template> cheers -- Andrew Welch http://andrewjwelch.com Kernow: http://kernowforsaxon.sf.net/
|
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
|