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

Re: What does name="{name()}" mean?

Subject: Re: What does name="{name()}" mean?
From: Syd Bauman <Syd_Bauman@xxxxxxxxx>
Date: Fri, 25 Dec 2009 12:58:15 -0500
Re:  What does name="{name()}" mean?
> Sometimes in templates a pattern like the following appear:
> <xsl:template .....>
>   <xsl:element name="{name()}" ....> 
>   ....
>   </xsl:element>
> </xsl:template>
> What do the curly brackets and name="{name()}" mean?

Hmm... other people who frequent this list are far more qualified to
provide a precise answer than I, but I can give you a quick idea.

The <xsl:element> element puts an element node onto the output tree.
The name of the element it puts on the output tree is specified by
the value of its name= attribute. So
    <xsl:element name="platypus">
      <xsl:attribute name="bill">duck</xsl:attribute>
      <xsl:text>Prius</xsl:text>
    </xsl:element>
puts 
   <platypus bill="duck">Prius</platypus>
into the output.

In XSLT, some attributes take as their value an "attribute value
template". The values of these attributes are "an alternating
sequence of fixed parts and variable parts. A variable part consists
of an XPath expression enclosed in curly brackets ({}). A fixed part
may contain any characters, except that a left curly bracket must be
written as {{ and a right curly bracket must be written as }}."

So the curly braces mean "evaluate my contents as an XPath
expression". The expression, here, consists of a call to the name()
function, which returns the fully qualified name (i.e., both the
namespace part and the local part) of the name of the node that is
passed to name(), or (as is the case here) by default the context
node (i.e., name() is the same as name(.)).

I think this has pretty much the same net effect as
    <xsl:element name="{local-name()}" namespace="{namespace-uri()}">
which I prefer only because it is more explicit.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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