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

RE: How to copy a string containing attributes into an

Subject: RE: How to copy a string containing attributes into an element?
From: "Michael Kay" <mhk@xxxxxxxxx>
Date: Wed, 30 Jun 2004 16:24:07 +0100
xsl function example
Don't try to serialize the attributes yourself (as a string), let Saxon do
the work for you. Create the attributes as nodes, not as strings.

Since you're using syntax that's special to Saxon already, you really might
as well move to XSLT 2.0 and use the replacement for these constructs
proposed in the current working drafts.

The natural thing to do would then be for your function to return a sequence
of attribute nodes, like this:

<xsl:function name="fun:GetAppearance" as="attribute()*">
  <xsl:param name="appearance"/>
  <xsl:attribute name="border" select="fun:GetBorder(XPATH)"/>
  <xsl:attribute name="background-color" select="fun:getColor(XPATH)"/>
  <xsl:sequence select="fun:getMargin(XPATH)"/>
</xsl:function>

You can then attach these attributes to an element with:

<fo:some-element>
  <xsl:sequence select="fun:getAppearance($a)"/>
</fo:some-element>

XSLT 1.0 doesn't allow freestanding attribute nodes, so the nearest
equivalent would be to create an element, attach the new attributes to it,
and return a temporary tree containing this element; you can then copy the
attributes to a different element using 

<xsl:copy-of select="fun:getAppearance($a)/*/@*)"/>.

Michael Kay


> -----Original Message-----
> From: Jan Kohnert [mailto:J.Kohnert@xxxxxxxxxxx] 
> Sent: 30 June 2004 15:22
> To: 'xsl-list@xxxxxxxxxxxxxxxxxxxxxx'
> Subject:  How to copy a string containing attributes 
> into an element?
> 
> Hello List,
> 
> In my stylesheet, I perform two steps to generate FO. First, 
> I dissolve any
> references inside the XML source data, building an temporary 
> result tree.
> Second, I apply over the temporary result tree, generating the FO code
> itself.
> 
> While dissolving the references I use saxon's "function" 
> extension to return
> the dissolved values.
> To apply succesfully over the tempory result tree, I need to store any
> information stored in FO as attributes also as attributes in 
> the temporary
> result tree.
> 
> Therefor I want to copy a string as returned from the 
> function example below
> into an element as a "attribute set": (X PATH is short for 
> the real X Path,
> that is quite long..)
> 
> <saxon:function name="fun:GetAppearance">
> <xsl:param name="appearance"/>
> <xsl:variable name="Appearanceset">
> <xsl:value-of select="concat( 'border=&quot;', fun:GetBorder( 
> X PATH ),
> '&quot; ',
>                               'background-color=&quot;', 
> fun:GetColor( X
> PATH ), '&quot; ',
>                               fun:GetMargin( X PATH ))"/>
> 
> </xsl:variable>
> <saxon:return select="$Appearanceset"/>
> </saxon:function    
> 
> Returns (for example): 
> border="0.5pt solid #FFAAAA" background-color="#CDCDCD" margin=""
> margin-top="5mm" margin-bottom="7mm" margin-right="2mm" 
> margin-left="5mm" 
> 
> (There is also a concat in "fun:GetMargin()" !)
> 
> what I want is, for example, to put this string into an 
> <block-container>
> element.
> <block-container border="0.5pt solid #FFAAAA" 
> background-color="#CDCDCD"
> margin="" margin-top="5mm" margin-bottom="7mm" margin-right="2mm"
> margin-left="5mm" >
> 
> Is this possible? and when, how?
> 
> Thanks!
> 
> --+------------------------------------------------------------------
> XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail: <mailto:xsl-list-unsubscribe@xxxxxxxxxxxxxxxxxxxxxx>
> --+--
> 
> 


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.