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

Re: handling tags and PIs within a macro

Subject: Re: handling tags and PIs within a macro
From: Abel Braaksma <abel.online@xxxxxxxxx>
Date: Wed, 24 Oct 2007 15:46:49 +0200
Re:  handling tags and PIs within a macro
Nancy Brandt wrote:
<formalpara id="{fid}"> --> This part

Why is it important to enclose the "id" part in curly
brackets?

That's a way to tell the XSLT processor that inside the attribute there's a value that should be interpreted as an XPath expression. It is called an Attribute Value Template (or AVT for short). You can write:


<formalpara>
   <xsl:attribute name="id"><xsl:value-of select="fid" /></xsl:attribute>
</

Or you can write:

<formalpara id="{fid}">
</

which is quite shorter and closer to what it will eventually look like: an element with the "id" attribute set to whatever is in inside the 'fid" node (without curlies, this would be the literal "fid" string, instead of the content of <fid>). If you, for whatever reason, need an explicit { or } inside an attribute, you need to double it:

<formalpara id="{{doublecurlies}}">
</

You can use any valid XPath expression. It's result will be the string-value of that expression (equal to when you would use the xsl:value-of approach instead). Now you may wonder why there's still the verbose construct with xsl:attribute, if this is so much clearer with an AVT. Well, the short answer is: there are situations where an AVT does not suffice. I.e., when you want the name of the attribute to be dynamically generated, then, inside the xsl:attribute, the @name attribute itself is also an AVT:

<formalpara>
<xsl:attribute name="{attrName}"><xsl:value-of select="fid" /></xsl:attribute>
</


will create a formalpara element with an attribute with the name of whatever is inside the attrName element. If the source looked like <attrName>my-jolly-attribute</attrName><fid>Fidelity Content</fid> then the output would be

<formalpara my-jolly-attribute="Fidelity Content">
</


HTH, Cheers, -- Abel Braaksma

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.