Novell Home

Assigning Attribute Values to Variables

Novell Cool Solutions: Trench
By Volker Scheuber

Digg This - Slashdot This

Posted: 13 Nov 2003
 

The Problem

I want to assign the value of the modified attribute (SB-TIPSOL) to a variable (VAR-TIPSOL), can someone toss me an example?

The Solution

A modify event has only (but always) 2 possibilities to manipulate an attribute: it can remove values and it can add values.

You said you want to capture the value of the modified attribute, so I assume you want to capture the new value (if there is one) of the attribute.

The other question is, how to design your template. e.g.: if you need to do other transformations on the same modify event and these other transformations need the variable you're trying to assign, I'd suggest you match on the "root" of the modify event. if, on the other hand, you only need the variable once for a specific calculation, I suggest matching at the deepest possible level. the following two templates should both do what you want, but only one might really fit your needs in the context of the whole style sheet:

<!-- match the root of modify events for class user. -->
<xsl:template match="modify[@class-name='User']">
<!-- only capture the new value and only the first, if multiple values have been added. note: the variable will be empty, if only a value has been removed. -->
<xsl:variable name="VAR-TIPSOL" select="./modify-attr[@attr-name='SB-TIPSOL']/add-value/value[1]"/>
</xsl:template>

<!-- match at the deepest possible level. this matches only the first value that has been added to the attribute. -->
<xsl:template match="modify[@class-name='User']/modify-attr[@attr-name='SB-TIPSOL']/add-value/value[1]">
<!-- the variable is somewhat superficious, as the variable name is already longer than the xPath statement "." (dot). -->
<xsl:variable name="VAR-TIPSOL" select="."/>
</xsl:template>


Novell Cool Solutions (corporate web communities) are produced by WebWise Solutions. www.webwiseone.com

© 2014 Novell