xsl-list
[Top] [All Lists]

Re: [xsl] select attribute of xsl:variable

2010-09-01 06:42:39
pankaj(_dot_)c(_at_)thomsondigital(_dot_)com wrote:

I have a piece of an XML, looks like below. I am trying to add an attribute to the matching element to corresponding @role value defined in the variable. The first case seems to be working well but secondly one fails and it looks that conditional check with @select attribute (select="parent::textbox-body/parent::textbox[(_at_)role]") in variable is failing. Can't we condition checks with ancestors/parent values in child elements.

What exactly happens when you say "is failing"? Do you get an error? Which one exactly?
Or which output do you want and which output do you get?

<xsl:template match="display/textbox">
<xsl:variable name="role_title" select="@role"/>
<xsl:variable name="boxtype">
<xsl:choose>
<xsl:when test="$role_title = 'alt1'">TE A title</xsl:when>
<xsl:when test="$role_title = 'alt2'">TE B title</xsl:when>
<xsl:when test="$role_title = 'alt3'">TE C title</xsl:when>
<xsl:when test="$role_title = 'alt4'">TE D title</xsl:when>
<xsl:when test="$role_title = 'alt5'">TE E title</xsl:when>
<xsl:when test="$role_title = 'alt6'">TE F title</xsl:when>
<xsl:when test="$role_title = 'alt7'">TE G title</xsl:when>
<xsl:when test="$role_title = 'alt8'">TE H title</xsl:when>
<xsl:when test="$role_title = 'alt9'">TE I title</xsl:when>
<xsl:when test="$role_title = 'alt1'">TE J title</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="aid:pstyle"><xsl:value-of select="$boxtype"/></xsl:attribute>
<xsl:copy-of select="@*"/>

So here you are outputting the attribute "aid:pstyle" on the copied "textbox" element.

<xsl:template match="display/textbox/textbox-head/title">
<xsl:variable name="role_title" select="parent::textbox-body/parent::textbox[(_at_)role]"/>
<xsl:variable name="boxtype">
<xsl:choose>
<xsl:when test="$role_title = 'alt1'">TE A title</xsl:when>
<xsl:when test="$role_title = 'alt2'">TE B title</xsl:when>
<xsl:when test="$role_title = 'alt3'">TE C title</xsl:when>
<xsl:when test="$role_title = 'alt4'">TE D title</xsl:when>
<xsl:when test="$role_title = 'alt5'">TE E title</xsl:when>
<xsl:when test="$role_title = 'alt6'">TE F title</xsl:when>
<xsl:when test="$role_title = 'alt7'">TE G title</xsl:when>
<xsl:when test="$role_title = 'alt8'">TE H title</xsl:when>
<xsl:when test="$role_title = 'alt9'">TE I title</xsl:when>
<xsl:when test="$role_title = 'alt1'">TE J title</xsl:when>
</xsl:choose>
</xsl:variable>
<xsl:copy>
<xsl:attribute name="aid:pstyle"><xsl:value-of select="$boxtype"/></xsl:attribute>

while here you are outputting the attribute "aid:pstyle" on the copied "title" element.

--

        Martin Honnen
        http://msmvps.com/blogs/martin_honnen/

--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--