Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


RE: [xsl] Attributes?

From: "Michael Kay" <mhk@--------->
To:
Date: 7/2/2004 10:08:00 AM
>     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}"/>
</xsl:function>

(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:

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

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


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent