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

RE: Attributes?

Subject: RE: Attributes?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Fri, 2 Jul 2004 09:07:43 +0100
xsl attributes select
>     In XSLT 1.0, match="g" matches exactly the same elements as 
>     match="//g".
>     There's a slight difference in 2.0, because match="//g" 
>     will only match g elements that are in a tree with a 
>     document node as its root - which means the processor has 
>     extra checks to do in this case.
> Confused. Don't *all* elements exist in a tree with a document
> node as its root?
> Under what circumstances might an element *not* have such a 
> root please?

No, XSLT 2.0 (and XQuery) allow you to create free-standing nodes. For
example, there was a question a few days ago (I think on the Saxon list
rather than here) from someone who wanted to write a function that returned
a set of attribute nodes:

<xsl:function name="my:atts" as="attribute()">
  <xsl:param name="p"/>
  <xsl:attribute name="a" select="{$p+1}"/>
  <xsl:attribute name="b" select="{$p+2}"/>

(Essentially the same as an attribute-set, except that attribute sets do not
allow parameters.)

You can copy these attributes to an element, like this:

 <xsl:copy-of select="my:atts(17)"/>

But you can also apply-templates to them:

<xsl:apply-templates select="my:atts(29)"/>

If you try to find the parent of one of these attributes, you find it hasn't
got one:

<xsl:value-of select="count(my:atts(6)/..)"/> displays "0".

And of course the same applies to elements.

Michael Kay

Current Thread


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.
First Name
Last Name
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.