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

RE: add an attribute to an element, then use it in an

Subject: RE: add an attribute to an element, then use it in another template
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Tue, 4 Mar 2008 19:07:04 -0000
RE:  add an attribute to an element
In XSLT 2.0 you can do:

<xsl:template match="music">
     <xsl:call-template name="attr">
          <xsl:with-param name="stuff" select="project"/>
     </xsl:call-template>
     <xsl:call-template name="attr">
          <xsl:with-param name="stuff" as="element()*">
             <project newThing="whoKnowsWhat"/>
             <project adadad="qwertyu"/>
          </xsl:with-param>
     </xsl:call-template
</xsl:template>

Alternatively you can do a 2-phase transformation: phase one takes the input
and adds a couple of attributes, phase 2 applies your current logic.

Michael Kay
http://www.saxonica.com/

> hi,
> i'm new using xsl, so please be patient... ;-)
> 
> the input is something like this:
> 
> <music>
> 
>     <project name="W.A.S.T.E">
>         <release name="We all seek total entropy" year="2003"/>
>         <release name="Violent delights" year="2006"/>
>     </project>
> 
>     <project name="Winterkalte">
>         <release name="Structures of Destruction" year="1997"/>
>         <release name="Drum 'n' noise" year="1999"/>
>     </project>
> 
> </music>
> 
> 
> the xsl:
> 
>     <xsl:template match="music">
>         <xsl:call-template name="attr">
>             <xsl:with-param name="stuff" select="project"/>
>         </xsl:call-template>
>     </xsl:template>
> 
>     <xsl:template name="attr">
>         <xsl:param name="stuff"/>
>         <xsl:for-each select="$stuff/@*">
> 
>         attrName: <xsl:value-of select="name()"/>
>         attrValue: <xsl:value-of select="."/>
> 
>         </xsl:for-each>
>     </xsl:template>
> 
> the output:
> 
> attrName: name
> attrValue: W.A.S.T.E
> 
> attrName: name
> attrValue: Winterkalte
> 
> 
> what i'm trying to do is add an attribute so the output will be:
> 
> attrName: newThing
> attrValue: whoKnowsWhat
> 
> attrName: name
> attrValue: W.A.S.T.E
> 
> attrName: name
> attrValue: Winterkalte
> 
> attrName: adadad
> attrValue qwertyu
> 
> i tried using <xsl:attribute> but i can't make it work... any ideas ?
> 
> thanks

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.